Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Message
| Well let's work through it. Logging in and typing the first line with a scripting prefix, nothing seems to happen:
/ res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264", "gmcpval", "room.info")
Now let's print the two values returned from CallPlugin:
I get:
0 {
coord = {
y = "20",
x = "30",
cont = "0",
id = "0",
},
num = "35233",
exits = {
e = "35235",
w = "35234",
s = "35229",
n = "35308",
},
terrain = "afountain",
details = "",
name = "Academy Courtyard Fountain",
zone = "academy",
}
The zero means "this went OK", and the rest is the GMCP stuff as a text string.
Now if I do the second line:
/ luastmt = "room = " .. gmcparg
And print the resulting variable:
I get:
room = {
coord = {
y = "20",
x = "30",
cont = "0",
id = "0",
},
num = "35233",
exits = {
e = "35235",
w = "35234",
s = "35229",
n = "35308",
},
terrain = "afountain",
details = "",
name = "Academy Courtyard Fountain",
zone = "academy",
}
That looks like something that will define a table. So we now evaluate that:
/ assert (loadstring (luastmt or "")) ()
That should have turned that Lua text into a table. Let's check:
/ require "tprint"; tprint (room)
I get:
"coord":
"y"="20"
"x"="30"
"cont"="0"
"id"="0"
"num"="35233"
"exits":
"n"="35308"
"e"="35235"
"s"="35229"
"w"="35234"
"details"=""
"terrain"="afountain"
"name"="Academy Courtyard Fountain"
"zone"="academy"
So now, room.num is our room number, like this:
Results:
So in short, to get the room number you would do this:
res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264", "gmcpval", "room.info")
luastmt = "room = " .. gmcparg
assert (loadstring (luastmt or "")) ()
room_number = tonumber (room.num)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|