[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Plugin callback functions

Plugin callback functions

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


Posted by Madcatz   (10 posts)  [Biography] bio
Date Wed 12 May 2010 03:32 PM (UTC)
Message
Do any of the OnPlugin* functions get called when the world is first opened? I have some tables that I'm serializing on OnPluginSaveState(), so that they're saved when the world is closed, but I'm not sure where I should be unserializing them. Most of the examples I see use OnPluginInstall(), but that doesn't seem to run if I just close the world and open it back up. I _could_ use OnPluginConnect(), but it's not uncommon for a user to disconnect and connect without the plugin saving state, in which case the tables would get overwritten -- though I suppose I could serialize in OnPluginDisconnect()...

Anyways, if I want the plugin to serialize and unserialize its tables so that they're not lost when the world is closed, where should I do this?

My current code is as follows:


function OnPluginSaveState()
  Note("OnSaveState")
  require "serialize"
  SetVariable ("captures", "captures = " .. serialize.save_simple (captures))
  SetVariable ("capturesecho", "capturesecho = " .. serialize.save_simple (capturesecho))
  SetVariable ("capturesordernums", "capturesordernums = " .. serialize.save_simple (capturesordernums))
  SetVariable ("capturesordernames", "capturesordernames = " .. serialize.save_simple (capturesordernames))
end

function OnPluginInstall()
Note("OnInstall")
assert (loadstring (GetVariable ("captures") or "")) ()
assert (loadstring (GetVariable ("capturesecho") or "")) ()
assert (loadstring (GetVariable ("capturesordernums") or "")) ()
assert (loadstring (GetVariable ("capturesordernames") or "")) ()
end


And it's not unserializing when I want it to (when I open the world after it's been closed).

And just to clarify: I actually _do_ need to serialize in order to save the tables when I close MUSHclient, yes?
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Wed 12 May 2010 06:04 PM (UTC)
Message
I'm nearly positive it is in fact being run. The reason you're not seeing "OnInstall" is because the output buffer hasn't been fully initialized by the time the plugins are called. Instead of using a Note() there, try a DoAfterSpecial():

DoAfterSpecial(5, [[Note("OnInstall")]], 12)


It should Note after 5 seconds.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Madcatz   (10 posts)  [Biography] bio
Date Reply #2 on Wed 12 May 2010 06:52 PM (UTC)
Message
Ah, you're right. I should be able to figure out what's going wrong now. Thanks :)
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Wed 12 May 2010 07:23 PM (UTC)
Message
It's easier to test this stuff by using "Reinstall" on the Plugins dialog with your plugin, for the record. No need to close and reopen the world, and the output buffer obviously is working.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Wed 12 May 2010 08:27 PM (UTC)
Message
You will simplify this stuff in the future if you put your variables into a "holding table", that way you just have to every serialize one thing, rather than having to add a line in the save function, and a line in the load function, for every extra variable you use.

eg.


myvars = {}

myvars.captures = 1
myvars.capturesecho = true
myvars.capturesordernums = 42
myvars.capturesordernames  = "swordfish"



Now just serialize "myvars".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


11,158 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]