Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Plugins
➜ Plugin variable scope
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kevnuke
USA (145 posts) Bio
|
Date
| Sat 30 Mar 2019 08:00 AM (UTC) |
Message
| 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? | Top |
|
Posted by
| Fiendish
USA (2,537 posts) Bio
Global Moderator |
Date
| Reply #1 on Sat 30 Mar 2019 02:27 PM (UTC) |
Message
|
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. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sun 31 Mar 2019 06:43 AM (UTC) |
Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Kevnuke
USA (145 posts) Bio
|
Date
| Reply #3 on Sun 31 Mar 2019 08:32 AM (UTC) |
Message
| Well then my next question is, how do I pass values or arrays between them, then? | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sun 31 Mar 2019 08:42 AM (UTC) Amended on Sun 31 Mar 2019 08:43 AM (UTC) by Nick Gammon
|
Message
| You can use CallPlugin:
Or you can retrieve client variables (not script variables) using GetPluginVariable:
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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sun 31 Mar 2019 08:47 AM (UTC) |
Message
| You could send tables by serializing them into a string. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
18,563 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top