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
➜ Plugin callback functions
|
Plugin callback functions
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Madcatz
(10 posts) 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? | | Top |
|
| Posted by
| Twisol
USA (2,257 posts) 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 | | Top |
|
| Posted by
| Madcatz
(10 posts) 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 :) | | Top |
|
| Posted by
| Twisol
USA (2,257 posts) 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 | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) 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 | | 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,340 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top