Global Framework

Global Framework

Download Plugin | Download Library | Video Tutorial | Discord Server

Features

Global Types                         "Access types from all other scripts"
Global Variables                     "Access variables from all other scripts"
Strict Mode                          "--!strict"
Circler Dependencies                 "Circler types + circler variables"
Inheritance                          "Inherit via 2 modes [Clone, Metatable]"
Automatic inherit dependency sorting "No mater what order your scripts run in"
Automatic generic dependency sorting "Global generic types will be listed in the correct order"
Diagnostics                          "Warnings if you define the same type or variable"
Comments Within Comments             "O_O"
Metatable Shortcut                   "Metatable types are very easy to type"
Style Flexibility                    "Does not enforce a specific style of writing code"
Modular                              "Only use parts of the global library you want"
Customizable                         "Very easy to add/modify/remove framework functions"

Support My Work

If you liked my work and want to donate to me you can do so here


SourceCode

You can get the sourcecode to this plugin/module here

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.


Quick Start

Step 1

"Make a ModuleScript and give it a attribute called GlobalTypes and set it to true"

690x458


Step 2

"Make a Script and require the ModuleScript we just made"

690x458


Step 3

"Make a type and block comment it out using --[[type]]"

690x458


Step 4

"Add a value into Global and set its type"

690x458


Done

"Congratulations you now have a global value that you can access in other scripts"

690x458


CLASS WITH METATABLE EXAMPLE

--!strict

--[[type MyGlobalClassType = {
    __index:                 MyGlobalClassType,
    new:                     (name: string, age: number) -> MyGlobalObjectType,
    SetName:                 (self: MyGlobalObjectType, name: string) -> (),
    SetAge:                  (self: MyGlobalObjectType, age: number) -> (),
}]]

--[[type MyGlobalObjectType  = {
    Name:                    string,
    Age:                     number,
} MyGlobalClassType]]

local Global = require(game.PathTo.ModuleScript)

local class = Global("MyGlobalIndex") :: Global.MyGlobalClassType
class.__index = class

function class.new(name, age)
    local self = setmetatable({}, class)
    self.Name = name
    self.Age = age
    return self
end

function class:SetName(name)
    self.Name = name
end

function class:SetAge(age)
    self.Age = age
end

CLASS WITHOUT METATABLE EXAMPLE

--!strict

--[[type MyGlobalObjectType  = {
    Name:                    string,
    Age:                     number,
    new:                     (name: string, age: number) -> MyGlobalObjectType ,
    SetName:                 (self: MyGlobalObjectType, name: string) -> (),
    SetAge:                  (self: MyGlobalObjectType, age: number) -> (),
}]]

local Global = require(game.PathTo.ModuleScript)

local class = Global("MyGlobalIndex", Global.Metatable()) :: Global.MyGlobalObjectType 

function class.new(name, age)
    local self = Global.Metatable(class) :: Global.MyGlobalObjectType
    self.Name = name
    self.Age = age
    return self
end

function class:SetName(name)
    self.Name = name
end

function class:SetAge(age)
    self.Age = age
end

CLASS WITHOUT NEW EXAMPLE

--!strict

--[[type MyGlobalObjectType  = {
    Name:                    string,
    Age:                     number,
    SetName:                 (self: MyGlobalObjectType, name: string) -> (),
    SetAge:                  (self: MyGlobalObjectType, age: number) -> (),
}]]

local Global = require(game.PathTo.ModuleScript)

local class = Global.Metatable() :: Global.MyGlobalObjectType 

Global("MyGlobalIndex", function(name, age)
    local self = Global.Metatable(class) :: Global.MyGlobalObjectType
    self.Name = name
    self.Age = age
    return self
end :: (name: string, age: number) -> Global.MyGlobalObjectType)

function class:SetName(name)
    self.Name = name
end

function class:SetAge(age)
    self.Age = age
end

Other Projects

Infinite Terrain
Suphi’s DataStore Module
Global Framework
Infinite Scripter
Mesh Editor
Toggle Block Comment
Toggle Decomposition Geometry
Tag Explorer
Suphi’s Linked List Module
Suphi’s Hybrid Linked List Module
Suphi’s RemoteFunction Module

28 Likes

Never knew block comments could be used like this! Cant wait to check it out.

Normally block comments don’t do anything but with the help of the plugin we can make some cool things happen :slight_smile:

if you run into any problems while checking it out report back and ill do my best to help

I’ve been enjoying using shared lately but it does lack autocomplete, I’m definitely gonna look into this because requiring modules, keep autocomplete and not having cyclic dependency issues is quite the headache.

eliminating cyclic modules is pretty bad, the error exists for a reason lmao

Why is it bad and what is the reason?

the modules end up being tightly coupled together which is a software nightmare, and it’s just complete violation of any code design principals

this isn’t really a framework per se, its more a global variable/type bootstrapper

Why is it bad to violate these coding design principles?

In order for something to be considered a framework what does it need to do/have?

8 Likes

Hello, this module is great but; Is there a way to update the variables and let other scripts access the updated variable? currently I have a whole table of variables and I’m setting elements of the table to a different value, but it doesn’t update on other scripts.

(sorry If I sound dumb, never used global variables like these before)

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.

1 Like

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?

1 Like

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:

2 Likes

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