Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
Entire forum
➜ MUSHclient
➜ Lua
➜ No SetPluginVariable function?
No SetPluginVariable function?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kevnuke
USA (145 posts) Bio
|
Date
| Mon 30 Apr 2012 06:38 AM (UTC) |
Message
| 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 30 Apr 2012 08:16 AM (UTC) |
Message
| Plugins are supposed to be independent. That was the design intention.
It's like saying "why doesn't my TV remote turn off my neighbour's TV?". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #2 on Mon 30 Apr 2012 08:25 AM (UTC) 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. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #3 on Mon 30 Apr 2012 08:50 AM (UTC) |
Message
| 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'.
SetPluginVariable() I am fully against, however. | Top |
|
Posted by
| Kevnuke
USA (145 posts) Bio
|
Date
| Reply #4 on Mon 30 Apr 2012 10:18 AM (UTC) |
Message
| 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. | Top |
|
Posted by
| Kevnuke
USA (145 posts) Bio
|
Date
| Reply #5 on Mon 30 Apr 2012 10:24 AM (UTC) |
Message
| 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. | Top |
|
Posted by
| Fiendish
USA (2,533 posts) Bio
Global Moderator |
Date
| Reply #6 on Mon 30 Apr 2012 12:09 PM (UTC) 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
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 |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Kevnuke
USA (145 posts) Bio
|
Date
| Reply #7 on Mon 30 Apr 2012 05:29 PM (UTC) |
Message
| 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? | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #8 on Mon 30 Apr 2012 07:24 PM (UTC) |
Message
|
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. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Nick Gammon
Australia (23,046 posts) Bio
Forum Administrator |
Date
| Reply #9 on Mon 30 Apr 2012 10:15 PM (UTC) |
Message
|
Kevnuke said:
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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Kevnuke
USA (145 posts) Bio
|
Date
| Reply #10 on Tue 01 May 2012 12:43 AM (UTC) |
Message
|
Nick Gammon said:
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. | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #11 on Tue 01 May 2012 10:09 AM (UTC) |
Message
| I am not the definite source on this, obviously, but I believe it saves state when:
- you save the world
- you unload or disable the plugin
- the SaveState() script function is called. | Top |
|
Posted by
| Kevnuke
USA (145 posts) Bio
|
Date
| Reply #12 on Tue 01 May 2012 04:25 PM (UTC) |
Message
| Awesome! I seemed to remember there being a SaveState function call. Thanks! | 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.
34,840 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top