Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Save state

Save state

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Tsunami   USA  (204 posts)  Bio
Date Fri 08 Sep 2006 05:41 PM (UTC)
Message
My understanding is that save state should be called only ONCE when a plugin is uninstalled.

It is possible, although unlikely that a plugin will change its state during the OnPluginSaveState callback. Thus if this function is called a second time during plugin save state, a different, and perhaps unwanted state would be saved. This is precisely what happens in my plugin.

I allow user 'plugins' to be added to my own plugin. A list of current plugins is stored in an table, so that the same plugins can be loaded next timer. In the OnPluginSaveState function, each plugin is uninstalled, giving it a chance to save it's own state. The list of plugins is serialized before the plugins are uninstalled. However, by the end of the OnPluginSaveState function, the table which holds current plugins is empty, since all plugins have technically been removed. Thus when OnPluginSaveState is called for a second time, the empty table is serialized, and on restarting MUSHclient, none of the appropriate plugins are loaded by my plugin.

It would be easy enough for me to change it so that the state was not changed during the course of OnPluginSaveState. However, doing some testing, I have found that upon closing MUSHclient, OnPluginSaveState appears to be called once. If the 'some world variables have changed... do you wish to save..?' dialog pops up, on clicking yes, state is saved again for the plugins, and it appears that perhaps the save state fuction is called a third time somewhere else during the close process, although I am not sure about the last one.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 08 Sep 2006 09:32 PM (UTC)
Message
Plugins save their state under two circumstances:


  • The world is being saved - thus if a user is connected for a long time, and wishes to save their world "just in case" it also saves the plugin states as well.

  • The plugin is being removed. Plugins are removed as a side-effect of the world being closed.


Thus if you save the world, and then close it, then the plugins will save their state twice.

I think it is a design flaw for the "save document" code in your plugin to change it. As a general rule in almost any program I can think of, you can always save the document to disk without worrying about it changing.

I suppose I could keep a flag "does the state need to be changed?". But the whole idea of the OnPluginSaveState callback is that you might need to serialize from internal variables (eg. Lua variables) into MUSHclient variables before saving. Thus MUSHclient doesn't really know if the extra save is necessary or not.

I suggest you change the OnPluginSaveState code so it can be safely called repeatedly. For instance, keep a separate list of the "user plugins" you are uninstalling, and work through that. But make it so that you can always re-save.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 08 Sep 2006 10:04 PM (UTC)
Message
A more logical place for you might be OnPluginClose - that is called when the plugin is being closed, which should only happen once.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tsunami   USA  (204 posts)  Bio
Date Reply #3 on Tue 12 Sep 2006 03:28 AM (UTC)
Message
Is OnPluginClose called when MUSHclient is closed. I don't believe it is; I have a plugin that takes around 10 seconds to save state, but there is no delay at all on closing MUSHclient.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #4 on Tue 12 Sep 2006 03:43 AM (UTC)
Message
It is called in the plugin destructor, so yes, it should occur on MUSHclient close.

I made a test by playing a sound in the OnPluginClose, and closed MUSHclient, and I heard the sound. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,695 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.