Is there any event fired by script reloading?

Posted by Hairui on Tue 05 Jun 2007 04:25 AM — 3 posts, 18,606 views.

China #0

Many things can be done after the script reloaded, but how I can do things such as saving the data before the script to be reload?


USA #1
Do you mean like with SetVariable and GetVariable? You can use those to save data over sessions, and the plugins keep their own save states with their own variables.
Australia Forum Administrator #2
There is no specific event, for the main script, when the script is reloaded. It wouldn't be reliable anyway, because people usually reload because the script has crashed.

In a plugin, you can use OnPluginSaveState function to save things before the plugin saves its state (which it does when it is being reloaded), or OnPluginClose, which is called when the plugin is being closed.

I would tend to keep stuff in plugins, once debugged, because of the automatic saving.

If you don't want to do that, you could save periodically (say, every minute or five), so that if you have to reload, you haven't lost everything.

Another thing you could do is make your own alias for reloading the script file, which first calls a function (to save stuff), and then does:


world.DoCommand "ReloadScriptFile"



Then make an accelerator to overload Shift+Ctrl+R, so that if you use that to reload the script file, it still calls your alias.

http://www.gammon.com.au/scripts/doc.php?function=Accelerator