Author Topic: Make an addon modify itself?  (Read 984 times)

Suppose you have variable $var, and you want to toggle it from 0 to 1 on the click of a button.  Is it possible for this change to stick around?

Method 1:
Use default prefs system

Any global var prefixed with $Pref:: will be saved to config/client/prefs.cs (unless you then add Server:: to it, which will be saved to the server folder)
Simply rename your global var to $Pref::var and it will be saved.

Method 2:
Export it yourself

Use this line of code
Code: [Select]
export("$var", "config/client/nameofmyaddon/prefs.cs");and it will be saved to that file. Saving other stuff to this file will overwrite it, so if you want to save multiple global vars, do something like this:
Code: [Select]
export("$MyAddonPrefs::*", "config/client/nameofmyaddon/prefs.cs");And use $MyAddonPrefs:: as a prefix. In that case,
$MyAddonPrefs::CoolVar1
$MyAddonPrefs::MyName
$MyAddonPrefs::ThCIAAPref
would all be saved to that file.

You would then execute that file as if it was a code file, to load the saved values.
Code: [Select]
exec("config/client/nameofmyaddon/prefs.cs");
« Last Edit: July 05, 2017, 06:49:52 PM by Crispy_ »

Method 1:
Use default prefs system

Any global var prefixed with $Pref:: will be saved to config/client/prefs.cs (unless you then add Server:: to it, which will be saved to the server folder)
Simply rename your global var to $Pref::var and it will be saved.

Method 2:
Export it yourself

Use this line of code
Code: [Select]
export("$var", "config/client/nameofmyaddon/prefs.cs");and it will be saved to that file. Saving other stuff to this file will overwrite it, so if you want to save multiple global vars, do something like this:
Code: [Select]
export("$MyAddonPrefs::*", "config/client/nameofmyaddon/prefs.cs");And use $MyAddonPrefs:: as a prefix. In that case,
$MyAddonPrefs::CoolVar1
$MyAddonPrefs::MyName
$MyAddonPrefs::ThCIAAPref
would all be saved to that file.

You would then execute that file as if it was a code file, to load the saved values.
Code: [Select]
exec("config/client/nameofmyaddon/prefs.cs");

thanks

Simply rename your global var to $Pref::var and it will be saved.

That's not all, you also have to make sure you don't just overwrite it with the default the next time the mod loads.

if ($Pref::Server::Blah $= "")
    $Pref::Server::Blah = "default value";


I use the default pref system for new dup if rtb/glass isn't available, you can see some examples here:
https://github.com/Zeblote/Tool_NewDuplicator/blob/master/scripts/server/prefs.cs
« Last Edit: July 06, 2017, 08:02:42 PM by Zeblote »