WoW:Saving variables between game sessions: Difference between revisions

m
Line 53: Line 53:
If your needs are simple, then you just have to mark your variable as saved in the <tt>.toc</tt> file, and initialize it with a reasonable default value at startup or OnLoad time. If there is a previously saved value, then it will simply overwrite the default one, otherwise the default value will remain. At the end of the play session whatever value it has ended up as will be saved.
If your needs are simple, then you just have to mark your variable as saved in the <tt>.toc</tt> file, and initialize it with a reasonable default value at startup or OnLoad time. If there is a previously saved value, then it will simply overwrite the default one, otherwise the default value will remain. At the end of the play session whatever value it has ended up as will be saved.


If your addon drives configuration from the saved variables, you will likely want to be informed when they've been loaded so the addon can reconfigure itself. In this case create an event handler and register for the <b>"ADDON_LOADED"</b> event, when the arg1 global variable has the name of your addon. Once this is called you can re-check your configuration and set things appropriately.
If your addon derives configuration from the saved variables, you will likely want to be informed when they've been loaded so the addon can reconfigure itself. In this case create an event handler and register for the <b>"ADDON_LOADED"</b> event, when the arg1 global variable has the name of your addon. Once this is called you can re-check your configuration and set things appropriately.


If your addon is not 'OnDemand' loaded, then you can also just use the "VARIABLES_LOADED" event.
If your addon is not 'OnDemand' loaded, then you can also just use the "VARIABLES_LOADED" event.
Anonymous user