Author Topic: Do global variables stick around after closing Blockland?  (Read 878 times)

Suppose you have $myVariable.  Through input, you set $myVariable to 1 on the first run of Blockland.  Does $myVariable continue being 1 when you turn Blockland on the next time? If not, how could this be possible?

No.

However, with export/exec, you can save variables and load them later.
For $myVariable specifically:
Code: [Select]
export("$myVariable","config/client/myvar.cs",0);
exec("config/client/myvar.cs");

However, saving one variable to it's own file isn't really necessary.
The args to export are as follows
export(search string, filepath string, append bool)
Something Blockland already does by default for a server is:
export("$Pref::Server::*","config/server/prefs.cs",0);
The * allows it to save multiple variables, like $Pref::Server::Name and $Pref::Server::Password, at the same time.

If you just wanted to add $myVariable to this file, you could just do
export("$myVariable","config/server/prefs.cs",1);
However, you'll need to figure out how to always do this after it exports itself, as the default export will not account for $myVariable, so it's not worth doing.
But still a good example of how to use the append.
« Last Edit: June 02, 2017, 11:05:51 PM by Shift Kitty »

No.

However, with export/exec, you can save variables and load them later.
For $myVariable specifically:
Code: [Select]
export("$myVariable","config/client/myvar.cs",0);
exec("config/client/myvar.cs");

However, saving one variable to it's own file isn't really necessary.
The args to export are as follows
export(search string, filepath string, append bool)
Something Blockland already does by default for a server is:
export("$Pref::Server::*","config/server/prefs.cs",0);
The * allows it to save multiple variables, like $Pref::Server::Name and $Pref::Server::Password, at the same time.

If you just wanted to add $myVariable to this file, you could just do
export("$myVariable","config/server/prefs.cs",1);
However, you'll need to figure out how to always do this after it exports itself, as the default export will not account for $myVariable, so it's not worth doing.
But still a good example of how to use the append.

If you're clever, as an addon maker, couldn't you use export/exec to make some sort of variable database so you don't clutter your own client/server files?

If you're clever, as an addon maker, couldn't you use export/exec to make some sort of variable database so you don't clutter your own client/server files?
What do you mean by this?

What do you mean by this?

Instead of taking up those precious three extra lines with defining global variables, instead offset all variable declarations to a special variable file/database with the commands you provided.

I'm not sure when you'd ever have to use more than one line to define a variable unless it was getting information from something not immediately accessible.

I'm not sure when you'd ever have to use more than one line to define a variable unless it was getting information from something not immediately accessible.

I asked because I have been scripting a GUI addon that I originally wanted to have an option where you disable it turning on as you start Blockland-- it simply sets $isEnabled to either "1" or "0" depending on input, so I'd need it to stick around to work properly.

If you're clever, as an addon maker, couldn't you use export/exec to make some sort of variable database so you don't clutter your own client/server files?
if it's something you need to change and load, yes

if it's just constant each time, the no, since you'll still have to define it the first time regardless

I asked because I have been scripting a GUI addon that I originally wanted to have an option where you disable it turning on as you start Blockland-- it simply sets $isEnabled to either "1" or "0" depending on input, so I'd need it to stick around to work properly.

If your variable starts with $Pref::, like $Pref::BlahMod::OpenOnStart, it will be saved automatically.
You just have to be careful that you don't overwrite it with the default value if it's already set, like this:

if($Pref::BlahMod::OpenOnStart $= "")
    $Pref::BlahMod::OpenOnStart = true;