That's right, but there is a OnPluginSaveState script callback that is called when you are about to save state. So that is the place to do it.
Awesome! That's what I was looking for.
Nick Gammon said:
Being able to set a variable from another plugin doesn't help in that respect.
In fact it would just be extremely confusing. Imagine if plugin A tried to save its state but before it could do that it had to set variables in plugin B which then had to set variables in plugin C and so on.
The logical way of handling that is to accept plugin callbacks (CallPlugin) so you can tell another plugin something (and get data back from it) in a controlled, published way.
Agreed, that would be confusing. Which is why I'm not trying to do that.
I have a single plugin and I was concerned with saving the values of variables in that plugin into MUSHclient world file variables. The ones you see when you hit Alt-Enter and select Variables. and then maybe use the same MUSHclient function to put them back. This was the reasoning behind SetPluginVariable acting the same as GetPluginVariable.
BUT, now that I know how that works I guess that's not really necessary.
Can you provide a list of all the actions that provoke MUSHclient to make a plugin save it's state? Oh and my other thread was actually giving me more of a headache than this one.. I was hoping you or Twisol would see it. It's a bit complicated..to me anyway.
I don't think it will save Lua variables or tables. I have to serialize them and save them using SetVariable, correct?
That's right, but there is a OnPluginSaveState script callback that is called when you are about to save state. So that is the place to do it.
Being able to set a variable from another plugin doesn't help in that respect.
In fact it would just be extremely confusing. Imagine if plugin A tried to save its state but before it could do that it had to set variables in plugin B which then had to set variables in plugin C and so on.
The logical way of handling that is to accept plugin callbacks (CallPlugin) so you can tell another plugin something (and get data back from it) in a controlled, published way.
Kevnuke said: Okay, I have save_state="y" already, but what's the extent of the variables it will save? I don't think it will save Lua variables or tables. I have to serialize them and save them using SetVariable, correct?
Correct.
Kevnuke said: Even after all this I need a way to force the plugin to save it's state AND it needs to survive clicking the reinstall button on the plugins window. Or does it already do that?
It already does that. MUSHclient knows to save and load state at certain points in the plugin lifecycle. You can view the statefile of a plugin (if one exists) by double right-clicking on the plugin in the plugin list.
Okay, I have save_state="y" already, but what's the extent of the variables it will save? I don't think it will save Lua variables or tables. I have to serialize them and save them using SetVariable, correct?
Even after all this I need a way to force the plugin to save it's state AND it needs to survive clicking the reinstall button on the plugins window. Or does it already do that?
Amended on Mon 30 Apr 2012 12:12 PM (UTC) by Fiendish
Message
Quote: I was actually more interested in using it to save the last value of a variable in a MUSHclient variable so it could later be assigned back to the same plugin variable
Plugins can already save state if you tell them to, so what you're asking for is a bad way of doing something we already have.
put
save_state="y"
in the plugin parameters section at the very top of the plugin (near author and date written, etc).
and then call SetVariable to persistently save plugin variables
I had the idea that if you did go ahead with making SetPluginVariable it could be similar to GetPluginVariable by using an empty string as the first argument to use it on MUSHclient world variables. Never know how useful it could be just to have. If the value argument in the function were a table it could automatically assign a MUSHclient variable the "array" type.
I was actually more interested in using it to save the last value of a variable in a MUSHclient variable so it could later be assigned back to the same plugin variable. I keep having to reinstall my plugin after a minor change and repeatedly logging out and back in to prevent certain variables from having a nil value is getting incredibly tedious.
I can see the value in a plugin accessing and perhaps modifying the main world variables. It's an accessible, not too difficult way to share information/state across plugins for the beginning scripter. CallPlugin() and varieties tend to be more difficult.
And for the end user, it is really simple to just tell them 'modify target in your variables and the plugin picks it up'.
Amended on Mon 30 Apr 2012 08:26 AM (UTC) by Twisol
Message
You really don't want to do that.
No, really.
I'm serious.
...If you insist, you can use CallPlugin("id", "SetVariable", "name", "value"). This only works for plugins - you can't CallPlugin() into the world environment. This also only works in Lua because of the multiple parameters.
Just wondering why there is no such function. And now for the (probably) stupid question. Can SetVariable be used to set a MUSHclient world variable from a script in a plugin?
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.