I am learning Lua and wanted to try and use the GMCP data to play around. My first function was going to grab the stats of my character and send them to a designated channel. I wrote an alias called ReportStats that takes one variable. It uses a regular expression and looks like this:
The alias calls the function ReportStats from my script file. The problem I'm running into is twofold. First, through some testing when I try and pass the variable from the alias to the function it is showing up as null when I print it. In the alias I just have ReportStats(%1).
Is that wrong? The function is below.
The second issue is that when I forced the variable chan to be 'spouse', I am getting that send and execute are nil global variables. The error is below:
So to recap, the first problem is figuring out how to get the alias to pass the variable successfully to the script. The second problem is how to send the information to the channel. FYI, if I substitute print for send in the above function, it does work.
M
^ReportStats (.*?)$
The alias calls the function ReportStats from my script file. The problem I'm running into is twofold. First, through some testing when I try and pass the variable from the alias to the function it is showing up as null when I print it. In the alias I just have ReportStats(%1).
Is that wrong? The function is below.
function ReportStats (chan)
res, gmcptext = CallPlugin("3e7dedbe37e44942dd46d264","gmcpval","char.stats")
luastmt = "charstats = " .. gmcptext
assert (loadstring (luastmt or "")) ()
if chan == nil then
chan = 'spouse'
end
myStr = tonumber(charstats.str)
myDex = tonumber(charstats.dex)
myCon = tonumber(charstats.con)
myWis = tonumber(charstats.wis)
myInt = tonumber(charstats.int)
myLuck = tonumber(charstats.luck)
myDr = tonumber(charstats.dr)
myHr = tonumber(charstats.hr)
myChan = tostring(chan)
send (myChan .. " Str: " .. myStr .. " Dex: " .. myDex .. " Con: " .. myCon .. " Wis: " .. myWis .. " Int: " .. myInt .. " Luck: " .. myLuck .. " DR: " .. myDr .. " HR: " .. myHr)
end
The second issue is that when I forced the variable chan to be 'spouse', I am getting that send and execute are nil global variables. The error is below:
Run-time error
World: Aardwolf
Immediate execution
[string "Script file"]:30: attempt to call global 'send' (a nil value)
stack traceback:
[string "Script file"]:30: in function 'ReportStats'
[string "Alias: "]:3: in main chunk
Error context in script:
26 : myDr = tonumber(charstats.dr)
27 : myHr = tonumber(charstats.hr)
28 : myChan = tostring(chan)
29 :
30*: send (myChan .. " Str: " .. myStr .. " Dex: " .. myDex .. " Con: " .. myCon .. " Wis: " .. myWis .. " Int: " .. myInt .. " Luck: " .. myLuck .. " DR: " .. myDr .. " HR: " .. myHr)
31 : end
So to recap, the first problem is figuring out how to get the alias to pass the variable successfully to the script. The second problem is how to send the information to the channel. FYI, if I substitute print for send in the above function, it does work.
M