Plugin variable scope

Posted by Kevnuke on Sat 30 Mar 2019 08:00 AM — 6 posts, 25,364 views.

USA #0
I tried looking around for this but couldn't find anything specifically addressing it.

I'm just trying to figure out if the variables in a plugin and my script file, or even the command line, are all in the same script space. Can I do
_G["testvariable"] = "foo"

in a plugin and then
print (testvariable)
-> foo

in a script file function/CLI or vice versa and have it act as I'd expect?
USA Global Moderator #1
Quote:
I'm just trying to figure out if the variables in a plugin and my script file, or even the command line, are all in the same script space


They aren't.

Quote:
Can I do...


You can try it and find out.
Australia Forum Administrator #2
Since plugins can be written in different languages (eg. Lua, Python, VBscript) it would be impossible for them to share the same variables.

Also the main world has its own script space, as Fiendish said.
USA #3
Well then my next question is, how do I pass values or arrays between them, then?
Australia Forum Administrator #4
You can use CallPlugin:

Template:function=CallPlugin
CallPlugin

The documentation for the CallPlugin script function is available online. It is also in the MUSHclient help file.



Or you can retrieve client variables (not script variables) using GetPluginVariable:

Template:function=GetPluginVariable
GetPluginVariable

The documentation for the GetPluginVariable script function is available online. It is also in the MUSHclient help file.



CallPlugin is more interactive, you actively call a function in another plugin, passing a value (or multiple values). GetPluginVariable lets you retrieve a variable from another plugin, assuming you realize you need to do that.

You can also "Execute" an alias, which another plugin can pick up. eg.


Execute "somerandomstring 666"


So then you make an alias in the target plugin which matches "somerandomstring *" and the number 666 then gets passed to that plugin.
Amended on Sun 31 Mar 2019 08:43 AM by Nick Gammon
Australia Forum Administrator #5
You could send tables by serializing them into a string.