PDA

View Full Version : How to create variables that persist after HoN restart.



picklefish
09-30-2009, 11:21 PM
[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:

String picklefish_mod_version

Your Variable:

int picklefish_mod_x


SetSave('variable_name', value);
This function sets your variable. On HoN restart this gets written to Startup.cfg


Initializing:
At the top of main.interface (this makes it so people don't have to restart HoN the first time) add:


<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')
)
);"
/>
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.


Updating Variable:
Every time you want to update your variable (picklefish_mod_x) you call SetSave('picklefish_mod_x', 1);
or
SetSave('picklefish_mod_x', 0);
or whatever value you want to set to it.


Patching Mod:
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.


Other notes:
You can actually check every variable if you want. Instead of checking version you would do this for every one.


<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)
)
);"
/>
Keep in mind that this seems to be very buggy/hard to get perfect.
Hope this helps. Check out my Stats mod in my signature to see how I do it. Look in the

SLeePz
10-01-2009, 01:04 AM
fish flavored pickles doesnt sound to tastey =/

gwho1
10-12-2009, 10:16 PM
but pickle flavored fish is a ocmpletely different story

very useful stuff in the original post, picklefish

grohn
12-14-2009, 03:49 PM
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

Barter
01-17-2010, 10:59 PM
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
^ this

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)

Jager
01-18-2010, 12:00 AM
even on the HoN options themselves (if you join a game, change the sound volume or graphics and disconnect, those changes are not saved)
Oh is that why that was happening sometimes. I hope S2 sees this!

grohn
01-30-2010, 12:34 PM
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()

eYo
02-28-2010, 05:49 AM
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.

BASH
02-28-2010, 10:30 AM
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()
Thanks for sharing!

eYo
02-28-2010, 03:08 PM
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... :(

grohn
02-28-2010, 05:34 PM
Disregard what I have said. The whole OptionsOpen(), OptionsApply() doesn't seem to work 100% of the time.

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... :(
You can either save through a normal UI command, SetSave(variablename), or through the console, Cmd('SetSave variablename value')

DarkZero901
05-26-2010, 08:08 PM
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.

DarkZero901
06-03-2010, 05:26 PM
Guess there isn't a way?