Plugin with saved states

Posted by Simon on Wed 06 Aug 2008 09:49 AM — 7 posts, 27,870 views.

Sweden #0
Hi,

I'm currently working on a bunch of stat-keeping plugins and I haven't really found anyway to keep plugin-data throughout sessions. The way it works with the normal world-file is that whenever you press ctrl-s it saves the states of all variables etc. This does not seem to be the case with plugins.

Is there anyway I can work around this?

Cheers
/Simon
Netherlands #1
First of all, you should check if the plugins in question have the save_state flag set to yes. Maybe it's called slightly differently, but it is one of the options in the plugin wizard, so make a dummy plugin to check it (got no MUSHclient to check with atm.)

Second, you should make sure you are using MUSHclient variables, and not Lua variables (or whatever other language you may be using). Those aren't saved.

However, you can save those Lua variables from the OnPluginSaveState() callback by manually saving those values to a MUSHclient variable, and restoring them upon loading. Check the rest of the forums for examples - it's been done to death. :)
Sweden #2
Hey!

And thanks for the help! I'm currently running my plugins with save_state="y". Maybe it's because I've been editing the plugin while having it running that the state hasn't been saved? I'm not sure. I'm not using script-variables, I'm using standard world (mush) variables for the information I want to save.

I guess that I don't have that problem then, although sometimes I have seen the error-message in mushclient that it couldn't save the state of the plugin. Does anyone know why that happens?

-- Edit
Now that I take a further look at it, that's exactly what the problem is. I have my plugins on an usb-memory, and it can't save the plugin-states to it. It says it can't create the file. Although I'm certain that the memory isn't full and that there is no write-protection there.

The problem was that the "state" folder wasn't created. Once I created that, the problem was solved.

Thanks for the help!

-- /Edit

Cheers,
Simp
Amended on Wed 06 Aug 2008 11:42 AM by Simon
Netherlands #3
I'm glad to hear your problem was solved. =)
Sweden #4
Hey again,

Now when I've had the time to look a bit more into the problem, there's another issue.

When I reload a plugin (which I do very often, since I work with them while using them), it overwrites the variables when I reload the plugin. Is there any way to set the variables to something in the script-file so they're not overwritten when reinstalling the plugin?

Best regards,
Simon
Australia Forum Administrator #5
Check out this link near the bottom:

http://www.gammon.com.au/forum/?id=4960

Any variables you want to keep should be "serialized" as in the example, and loaded back in. That preserves them, even if you do a "reinstall plugin".

Don't use variables in the plugin file itself if you can help it. Because of the load order they will overwrite any changes you make by serializing them.
Sweden #6
I made something similiar to what you suggested nick, and it's working flawless! Awesome! Thanks for all the help!

Cheers,
Simp.