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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  No SetPluginVariable function?

No SetPluginVariable function?

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


Posted by Kevnuke   USA  (145 posts)  [Biography] 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?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] 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
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] 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.
[Go to top] top

Posted by Kevnuke   USA  (145 posts)  [Biography] 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.
[Go to top] top

Posted by Kevnuke   USA  (145 posts)  [Biography] 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.
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] 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

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

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Kevnuke   USA  (145 posts)  [Biography] 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?
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by Kevnuke   USA  (145 posts)  [Biography] 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.
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] 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.
[Go to top] top

Posted by Kevnuke   USA  (145 posts)  [Biography] 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!
[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.


32,545 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]