Shared variables across modules

Is there a straight forward way to share a variable between all modules in a plugin?

Perhaps something like this would work for you:

Save location of global config for plugin?

I use this in Impromptu and Geodesics to store the default state of the panel theme.

More reading that might interest you:

1 Like

Already doing exactly that for the same reason.

I note that I can share a variable across all instances of a specific module, just wondered if there was an easy way to do the same across all instances of all modules in a plugin.

It should work the same way no? In my case, the default color variable that is shared can be read by all modules in the plugin.

I use RacketScience.json for persistence between instances of rack.

I have a shared variable at run time so when an instance of the module changes it the change is immediately visible across all instances of that specific module, I’d like to share that across all instances of all modules in my plugin if possible, in memory, not by reading and writing a file.

You can use a global, but make sure reads/writes are thread-safe.

If you need to save its state, the standard is that each plugin is allowed one global file or folder at <Rack user dir>/<plugin slug>[.ext].

1 Like

That’s what I’m doing, declaring a global in my module, that works across all instances of a module, I want it to work across all instances of all modules in the plugin, thought declaring it in plugin.hpp might work but apparently not.

Yes, that should work. Declare it with extern int variable; in plugin.hpp and int variable = default; in plugin.cpp.

1 Like

Sorted! Thank you.