Share variables between addons.

Hi people. I have a mod with a few clientside variables that need to be read by other clientside addons (HUD mods). Whats the best method to share data between addons? Is it safe to declare them as global variables? Or I should add some networking stuff like SetNW* ?

Can you be more specific what you need to access? Give examples

You can use global variables, which can be accessed by any script on the server.

The best way to do this is by using tables to organize your data in a way so that other addons that are declaring the same variable won’t (hopefully) override it.

addon1 example:


addon1data = {
    bool = true,
    int = 1,
    str = "Hello",
}

addon2 example:


print(addon1data.str)

would print “Hello”

My mod has a local variable called Luminocity, which is calculated clientside and then sent to the server (because I need the render library, which is clientside only). Every client has its own. There’s also a HUD with a bar that shows this variable. However, I want to make it compatible with other HUD mods, so they can show the same variable. I want this variable to be readable by other addons. Someone suggested me to use SetNWFloat. I’ve read a bit about those functions, and it seems to be used as a way to share data between server and client, through a entity, or something like that (I’m pretty new with LUA). But I don’t need to move data to the server, both mods (mine and the HUD mod) are clientside. Wouldn’t it work if I just declare my variable as global? Or I really need to add networking?

Edit: Oh, so a global variable will do. Whats “SetNW***” used for then? Is it better than the Net. library?

Global variables and the net library arent made for the same purpose…
The net library is for server and client communication.
Global variables is what you need.
Just remove the local before the variable and you should be good to go.