Global Framework

do you mind sharing your code so i can see what your doing

but if you make a table global all scripts will have access to that exact same table and any changes made to the table should be reflected to all scripts so i’m not really sure how you managed to not make it work correctly

1 Like

I love how their whole argument is “It violates some rule someone invented”, and then don’t question why it is bad.

2 Likes

I’m working on a custom physics character controller, I’m using the Global Framework module to store variables like velocity, position, etc…
I have a main module that updates the state machine and handles all client-related things; I’m also setting the Velocity of the character to the velocity value inside of the Global Framework.
StateMachine → Ground module:

--> runs every physics frame
Global.ClientShared.Velocity = Global.ClientShared.WishDirection
--> wishdirection is being set in ControlModule, works normally

print(Global.ClientShared.Velocity) --> output: the velocity vector (not Vector3.zero)

ControlModule (main module):

local Global = require(Libraries.Global);

--> runs every physics frame
Global.ClientShared.WishDirection = InputDirectionLocal --> works
print(Global.ClientShared.Velocity) --> Vector3.zero

LinearVelocity.VectorVelocity = Global.ClientShared.Velocity --> Vector3.zero

Global Script (RunContext to Client):

--[[type ClientShared = {.. Velocity: Vector3; ..}]]
Global('ClientShared', {.. Velocity = Vector3.zero; ..})

I’ve looked through everything, didn’t seem to see anything wrong that I did.

is this all happening on the client side

because global framework does not replicate over the network

also if your using the plugin then the plugin wont be able to understand your require()

yeah, it’s all clientsided

the statemachine is able to read updated values from the controlmodule but the controlmodule isnt reading updates from the statemachine.

by plugin i meant like the first part of your video (the Plugin section)

are they all running on the same actor?

yes but you only need the plugin if you want help with type checking if your not using type checking then you dont need the plugin

I’m not using an actor – here’s the structure (the global module is the framework, the script under it just defines the variables
image
the script inside:

--[[
	type ClientShared = {
		Position: Vector3,
		WishDirection: Vector3,
		Velocity: Vector3,

		LinearVelocity: LinearVelocity,
		AlignOrientation: AlignOrientation,
		Character: Model,

		IgnoreParams: RaycastParams,
	}
]]

local Global = require(script.Parent)

local ClientShared: Global.ClientShared = Global('ClientShared', {
	Position = Vector3.new(0, 4, 0),
	WishDirection = Vector3.zero,
	Velocity = Vector3.zero,

	LinearVelocity = nil,
	AlignOrientation = nil,
	Character = nil,

	IgnoreParams = RaycastParams.new(),
}) :: Global.ClientShared

the ControlModule is inside of the PlayerModule inside of StarterPlayerScripts.

edit* yeah, i’m using the plugin for intellisense

hum strange with the code you have shown everything looks like it should work i don’t see any problems with it

Are you setting velocity back to zero after physics step?

2 Likes

OH MY GOD. I just realised i kept changing it back to 0 for resimulating the movement when getting a snapshot from the server :sob:

thank you for making me realize that :pray: :sob: sorry for my stupidity…!!

i’m happy you solved your problem :grin:

3 Likes

Is it an intended feature that this only works for scripts inside ServerScriptService, or am I doing something wrong?

oh nvm, I’m stupid. scripts don’t work on serverstorage. couldve sworn it does though

if you set the scripts runcontext to legacy it wont run in server storage but if you set the runcontext to server or client it will run everywhere

this is just how roblox currently works has no relation to the framework

the reason is that when you dont follow these rules, your code becomes janky very quickly and easily breaks. that’s something that might happen while using this. also, thanks for loving my argument, i would say it is pretty crafty myself

You are still not elaborating on why it makes your code janky, stop playing dumb and explain already, I need to know. Prove me wrong or something already.

This is extremely inefficient for something simple

1 Like

what do you mean by eliminating cyclic modules?

To just clear up any confusion

  1. The Global Module, Plugin and Library does not have any circular dependencies within them

  2. The Global Framework does not force you to have circular dependencies but gives you the freedom to choose if you want them or not


For anyone that does not know what a circular dependency is here is a example

lets Imagen your making a minecraft style game and you have 2 objects/classes world and block

-- WorldModule
local Block = require(BlockModule)
local World = {}
local blocks = {} 

function World:SetBlock(blockType, x, y, z)
    blocks[x][y][z] = Block.new(blockType, x, y, z)
end

return World
-- BlockModule
local Block = {}

function Block.new(blockType, x, y, z)
    local block = {}
    block.Type = blockType
    block.X = x
    block.Y = y
    block.Z = z
    return block
end

return Block

Now at this time World requires Block but Block does not require World so there currently not cyclic but you might notice that even though we have no cyclic dependencies these 2 modules are highly coupled together World does not work without Block and Block does nothing without World ok lets now for example add a explode function for blocks and do it in a way that makes it cyclic

-- BlockModule
-- this is a cyclic require
local World = require(WorldModule)
local Block = {}

function Block.new(blockType, x, y, z)
    local block = {}
    block.Type = blockType
    block.X = x
    block.Y = y
    block.Z = z
    return block
end

function Block:Explode()
    for x = -1, 1 do
        for y = -1, 1 do
            for z = -1, 1 do
                World:SetBlock("Air", self.X + x, self.Y + y, self.Z + z)
            end
        end
    end
end

return Block

Now world and block are cyclic they require each other

Some people might say this is bad some might not but the good thing about this framework it gives you the freedom to choose

1 Like

Would you mind sharing what parts are inefficient so that i can improve them

Any tips on making them efficient would be greatly appreciated

also this framework is open source and if anyone wants to contribute any code towards the project id be happy to review any changes anyone puts forward

Global Library 1.1 published

Bug fix on the Thread script

no longer uses Tail Recursion because tail calls was removed from luau more information can be found here: Luau - Proper Tail Calls / Recursion - Not Working

1 Like