SUPPORT ACCOUNT CLANS
Welcome, Unregistered.
 

Thread: How to create variables that persist after HoN restart.

Results 1 to 13 of 13
  1. #1
    Offline
    Account Icon
    Join Date
    Jul 2009
    Posts
    444

    How to create variables that persist after HoN restart.

    [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:
    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')
                        )
                    );"
    />
    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.
    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)
                         )
                    );"
    />
    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
    Last edited by MaxGhost; 01-29-2010 at 12:09 PM.

  2. #2
    fish flavored pickles doesnt sound to tastey =/
    Howies Game Shack Employee - Westminster


  3. #3
    Offline
    Account Icon
    Join Date
    Oct 2009
    Posts
    847
    but pickle flavored fish is a ocmpletely different story

    very useful stuff in the original post, picklefish

  4. #4
    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

  5. #5
    Offline
    Account Icon
    Join Date
    Jul 2009
    Location
    Brazil
    Posts
    442
    Quote Originally Posted by AsiaPingPong View Post
    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)

  6. #6
    Offline
    Account Icon
    Join Date
    Jun 2009
    Location
    New Zealand
    Posts
    3,793
    Quote Originally Posted by Barter View Post
    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!

  7. #7
    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()
    Last edited by AsiaPingPong; 02-18-2010 at 03:51 PM.

  8. #8
    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.

  9. #9
    Quote Originally Posted by AsiaPingPong View Post
    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!

  10. #10
    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...

  11. #11
    Disregard what I have said. The whole OptionsOpen(), OptionsApply() doesn't seem to work 100% of the time.
    Quote Originally Posted by eYo View Post
    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')

  12. #12
    Offline
    Account Icon
    Join Date
    Aug 2009
    Location
    4.65 billion years
    Posts
    886
    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.
    True Skill Rating mod - a numerically simple but elaborate rating system used to judge the skill of players.


  13. #13
    Offline
    Account Icon
    Join Date
    Aug 2009
    Location
    4.65 billion years
    Posts
    886
    Guess there isn't a way?
    True Skill Rating mod - a numerically simple but elaborate rating system used to judge the skill of players.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •