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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  How to set a plugin variable's value in another plugin?
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

How to set a plugin variable's value in another plugin?

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


Posted by Jcl   (42 posts)  [Biography] bio
Date Sat 12 Nov 2005 07:21 AM (UTC)
Message
For example, I installed two plugins:
Plugin A has a variable named "skill".
In plugin B, now I can read it's value by world.GetPluginVariable(A, "skill"), but how can I change the value? Why not exist world.SetPluginVariable(A, "skill", "blade")?
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #1 on Sat 12 Nov 2005 01:14 PM (UTC)
Message
With the latest version you can use the BroadcastPlugin (or PluginBroadcast?) callback to send a message to any other plugins. The idea is that whoever catches the message can figure out what it means from its contents and perform any required actions.

For example, if your plugin B needs to set the "skill" variable in plugin A, it can send a message like "A_SetVariable_skill_value". Plugin A would then intercept this message and read it as:

"A" - this message is for plugin A.
"SetVariable" - I want you to set a variable
"skill" - this is the name of the variable you need to set
"value" - set the variable to this value.

Another way to do the same trick is to use aliases, which lets you communicate with the world file also, and not just other plugins.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #2 on Sat 12 Nov 2005 01:19 PM (UTC)
Message
http://files.tagworld.com/919de069bc64bf71492fb9f1d8cf1b1b72a7.xml

This is a plugin that defines a basic message protocol using aliases, and allows you to gather and display information about various messages that different parts of your system exchange with each other.

[Go to top] top

Posted by Nick Gammon   Australia  (21,609 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sat 12 Nov 2005 07:34 PM (UTC)
Message
It was a design decision to not let plugins or scripts change the variables of other plugins. Plugins are supposed to be self-contained, and the plugin author is entitled to think that its internal variables will not be changed without the plugin's consent.

However I could not see a problem with reading variables, so you can do that.

As Ked said, you can use a number of methods to "ask" a plugin to change its variables:


  • CallPlugin

  • Use an alias the plugin will intercept

  • OnPluginBroadcast


The advantage of these methods is that the plugin can intercept them and choose whether or not to set the variable, for example after validating it is in range. Also it may need to take action if the variable is changed.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


4,115 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 FutureQuest]