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.
Entire forum
➜ MUSHclient
➜ Lua
➜ Trouble with GetPluginVariable
Trouble with GetPluginVariable
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Rollanz
(26 posts) Bio
|
Date
| Sat 07 Nov 2015 11:28 PM (UTC) Amended on Sun 08 Nov 2015 03:57 AM (UTC) by Rollanz
|
Message
| I am trying to make the GMCP variables available to the general scripting space, through mediation of a plugin. In the plugin, I have a nested table called "vitals", and I'm trying to make an alias that can call information from the table. However, GetPluginVariable doesn't seem to be able to access the plugin.
vitals=GetPluginVariable("c19700e70d6a8d03b9866c24","vitals") --returned an empty value
vitals=GetPluginVariableList("c19700e70d6a8d03b9866c24") --returned a table of size 0
I double checked the ID of the plugin and the spelling of vitals. I also verified that IsPluginInstalled returned true for the plugin in question.
Thanks in advance for any help or insights.
The alias I'm using:
<aliases>
<alias
match="^update charvitals$"
enabled="y"
group="gmcp"
regexp="y"
send_to="12"
keep_evaluating="y"
sequence="100"
>
<send>require "tprint"
require "ppi"
vitals=GetPluginVariable("c19700e70d6a8d03b9866c24","vitals")
if vitals==nil then
print("vitals not found!")
end</send>
</alias>
</aliases>
And the script file from the plugin itself:
local PPI = require("ppi")
require "tprint"
require "json"
name=GetPluginID()
vitals={
hp = {curr=4500, max=4500},
mp = {curr=4500, max=4500},
ep = {curr=10000, max=10000},
wp = {curr=10000, max=10000},
nl = {curr=0, max=100},
}
charstats={}
statsArray={}
PPI.OnLoad("29a4c0721bef6ae11c3e9a82", function(gmcp)
gmcp.Listen("Char.Vitals", function(message, content)
content.maxnl = 100
for stat, data in pairs(vitals) do
data.curr = tonumber(content[stat] + 0)
data.max = tonumber(content["max" .. stat])
end
charstats=content["charstats"]
for k,v in pairs(charstats) do
local readout = {}
readout = utils.split(v,":")
statsArray[readout[1]]=string.sub(readout[2],2)
end
end)
end)
OnPluginListChanged = function()
PPI.Refresh()
end
OnPluginClose = function()
WindowDelete(name)
end
OnPluginEnable = OnPluginInstall
OnPluginDisable = OnPluginClose
| Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 08 Nov 2015 02:01 AM (UTC) |
Message
|
vitals=GetPluginVariable("c19700e70d6a8d03b9866c24") --returned a table of size 0
That should have failed:
[string "Command line"]:1: bad argument #2 to 'GetPluginVariable' (string expected, got no value)
I can't quite make out what you are doing. GetPluginVariable gets the contents of a variable setup by SetVariable in the plugin. However your plugin is not setting any variables. You are doing this in your alias:
However that alias does not use ppi. You seem to be combining a number of different methods here. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Rollanz
(26 posts) Bio
|
Date
| Reply #2 on Sun 08 Nov 2015 04:12 AM (UTC) |
Message
|
Nick Gammon said:
vitals=GetPluginVariable("c19700e70d6a8d03b9866c24") --returned a table of size 0
That should have failed:
[string "Command line"]:1: bad argument #2 to 'GetPluginVariable' (string expected, got no value)
-----
I can't quite make out what you are doing. GetPluginVariable gets the contents of a variable setup by SetVariable in the plugin. However your plugin is not setting any variables. You are doing this in your alias:
However that alias does not use ppi. You seem to be combining a number of different methods here.
Thank you, Nick, for the fast reply.
Sorry, the variation of the line should have been GetPluginVariableList, not GetPluginVariable. I've corrected the error in my opening post.
-----
I had misunderstood GetPluginVariable as operating on any element that I thought of as variables (including non-constant tables), which doesn't make sense now that you point it out. Is there a general method to retrieve table-type information from the plugin? One that hopefully doesn't involve converting to an intermediate string form? I'm guessing that I could pass it through json.encode and json.decode if all else fails?
Please don't mind the require "ppi". I have the bad habit of starting to including extra libraries when a piece of code isn't working the way I expected. | Top |
|
Posted by
| Nick Gammon
Australia (23,121 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 08 Nov 2015 08:31 AM (UTC) |
Message
| Different plugins have different script "execution" spaces (they may even be different languages). Hence communication between them cannot be by simple Lua tables. Things need to be converted into text format and back again (if you want to pass complicated stuff like tables).
You could use JSON, but the serialization functions that come with MUSHclient are a simpler way of achieving the same thing.
See: http://www.gammon.com.au/forum/?id=4960
This stuff is reasonably fast, I think Aardwolf uses it extensively, and it runs quickly. |
- 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.
13,941 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top