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

Posted by Jcl on Sat 12 Nov 2005 07:21 AM — 4 posts, 19,436 views.

#0
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")?
Russia #1
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.
Russia #2
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.

Australia Forum Administrator #3
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.