[Guide] How to create variables that persist after HoN restart.
After many headaches dealing with this I'm passing on my invaluable knowledge.
You need a variable for your version:
This function sets your variable. On HoN restart this gets written to Startup.cfg
At the top of main.interface (this makes it so people don't have to restart HoN the first time) add:
This checks if the version variable has been created and is equal to "version1.0", if it hasn't been, it will set them all.Code:<panel width="0h" height="0h" onload=" if( (!picklefish_mod_version) and (StringEquals(picklefish_mod_version, 'version1.0') != 0), Split( CreateInt('picklefish_mod_x', 1), SetSave('picklefish_mod_x', 1), CreateString('picklefish_mod_version', 'version1.0'), SetSave('picklefish_mod_version', 'version1.0') ) );" />
Every time you want to update your variable (picklefish_mod_x) you call SetSave('picklefish_mod_x', 1);
or whatever value you want to set to it.
If you are adding new variables simply change all cases of 'version1.0' to a new version like 'version1.1'.
If you are not adding new variables then you don't need to change anything.
You can actually check every variable if you want. Instead of checking version you would do this for every one.
Keep in mind that this seems to be very buggy/hard to get perfect.Code:<panel width="0h" height="0h" onload=" if( !picklefish_mod_x, Split( CreateInt('picklefish_mod_x', 5), SetSave('picklefish_mod_x', 5) ) if( !picklefish_mod_y, Split( CreateInt('picklefish_mod_y', 5), SetSave('picklefish_mod_y', 5) ) if( !picklefish_mod_z, Split( CreateInt('picklefish_mod_z', 5), SetSave('picklefish_mod_z', 5) ) );" />
Hope this helps. Check out my Stats mod in my signature to see how I do it. Look in the
Last edited by MaxGhost; 01-29-2010 at 01:09 PM.
but pickle flavored fish is a ocmpletely different story
very useful stuff in the original post, picklefish
Don't use SetSave(). Instead, use the console version Cmd('SetSave <variable name> <value>'), without the brackets. This will automatically create the variable if it does not already exist. SetSave() requires you to create a variable first.
By this method, you don't need to include the superfluous code at the beginning of main.interace
also using the cmd setsave fixes problems like the variables not saving if you disconnect (instead of closing/exiting) the game that exists on some mods and even on the HoN options themselves (if you join a game, change the sound volume or graphics and disconnect, those changes are not saved)
I did some more testing with this.
You only need to setsave the variable once. Ever.
The variable will be automatically saved when you close HoN.
Furthermore, you don't even need to setsave the variable the next time you run HoN.
Edit - Also, it appears that the only way to guarantee that it will save is to run the UICmd OptionsApply() after you change it.
Edit2 - In order to ensure that this does not crash the linux client, it is necessary to run OptionsOpen() before you do OptionsApply()
Is there any way of creating array variables? I like to create a StringArray to save all banned users from my banlist. So I can use them for other mods/scripts.
I'm still searchin for a way to save custom variables like CreateString("hello_" # param0);
I can create this variable and it works but if I use Cmd('SetSave(\'hello_\' # param0)'); the variable wont get restored after restarting HoN...
For some reason this isn't working for me.
I want to put some kind of line into my mod.xml that will cause the mod to automatically overwrite a line in the startup.cfg with another line.
I tried all variations of SetSave, but I think since the SetSave variable already exists in the startup.cfg, it doesn't overwrite it.
Guess there isn't a way?