WeeWillie
Content Creator
- Joined
- Nov 8, 2013
This is a continuation of a discussion started in the thread http://www.sdtmods.com/index.php?topic=5870.0 between me and Pim_gd. Seems like it should branch to its own thread and made public since it might be of value to others:
My understanding of how global variables are meant to work, supported through some testing and info from Dialogue Checker is as follows:
A global variable is first declared as any local variable in initial_settings:
The variable is then made global via a call to VA_SET_GLOBALVARIABLE, VA_SET_GLOBALVARIALBEBYNAME or VA_LOAD_GLOBALVARIABLE. For example, the following marks gMyVar as a global variable with its value set to 10 (note, this requires the fix that is going into DA 3.1. For DA 3.0 or earlier, you need to replace “10” with “+10” and have gMyVar initialized to 0)
This variable can now be used as any other local, though any setting of the variable will not affect the stored value. For example:
Will return “The value of gMyVar is 20”. However the stored value of the global will still be 10.
If a new dialogue is loaded, the local value of gMyVar will reset, losing the value of 20, but the following will restore it to the value of 10 in my example.
So in summary, the global variable is used in a dialogue like a local, and has a local value, but the local value is saved in global memory during a VA_SET_GLOBALVARIABLE and it restored from local memory with a VA_LOAD_GLOBALVARIABLE.
My new savegame functionality using [VA_SAVE_SAVEGAME_MYSAVE] and [VA_LOAD_SAVEGAME_MYSAVE] takes the values of all global variables stored in DA memory and either save or loads them to disk. As such, to avoid horrible maintenance and performance overhead of multiple VA_SET_GLOBALVARIABLE calls before making a save file, the calls do the following:
This seems like desired functionality, but Pim_gd, you seemed to stress that local and global need to be seperate and all global variables need to be manually handled by SETs and LOADs. Thoughts?
My understanding of how global variables are meant to work, supported through some testing and info from Dialogue Checker is as follows:
A global variable is first declared as any local variable in initial_settings:
Code:
initial_settings:{"gMyVar":0}
The variable is then made global via a call to VA_SET_GLOBALVARIABLE, VA_SET_GLOBALVARIALBEBYNAME or VA_LOAD_GLOBALVARIABLE. For example, the following marks gMyVar as a global variable with its value set to 10 (note, this requires the fix that is going into DA 3.1. For DA 3.0 or earlier, you need to replace “10” with “+10” and have gMyVar initialized to 0)
Code:
"[VA_SET_GLOBALVARIABLE_gMyVar_10]"
This variable can now be used as any other local, though any setting of the variable will not affect the stored value. For example:
Code:
"The value of gMyVar is *gMyVar*.” {“set”:{“gMyVar”:20}}
Will return “The value of gMyVar is 20”. However the stored value of the global will still be 10.
If a new dialogue is loaded, the local value of gMyVar will reset, losing the value of 20, but the following will restore it to the value of 10 in my example.
Code:
"[VA_LOAD_GLOBALVARIABLE_gMyVar]"
So in summary, the global variable is used in a dialogue like a local, and has a local value, but the local value is saved in global memory during a VA_SET_GLOBALVARIABLE and it restored from local memory with a VA_LOAD_GLOBALVARIABLE.
My new savegame functionality using [VA_SAVE_SAVEGAME_MYSAVE] and [VA_LOAD_SAVEGAME_MYSAVE] takes the values of all global variables stored in DA memory and either save or loads them to disk. As such, to avoid horrible maintenance and performance overhead of multiple VA_SET_GLOBALVARIABLE calls before making a save file, the calls do the following:
- VA_SAVE_SAVEGAME_ goes through the list of all globals and in essence performs a [VA_SET_GLOBALVARIABLEBYNAME_varName_varName] to store all the local values that might be hanging around and move them into DA memory before making the save.
- VA_LOAD_SAVEGAME_ loads up the saved version from disk of all the global variable, then it in essence performs a [VA_LOAD_GLOBALVARIABLE] on all variables to make sure they can be used in the dialogue.
This seems like desired functionality, but Pim_gd, you seemed to stress that local and global need to be seperate and all global variables need to be manually handled by SETs and LOADs. Thoughts?