Didn't see a thread for general questions about coding in Mudlet specifically, so here you go! I'll start.
I'm trying to make a script to track certain information via GMCP. The code looks like this:
function CharVitals(event,args)
cecho("stage1")
vitals = gmcp.Char.Vitals
cecho("stage2")
if vitals.herb == 1 then
balance.herbs = true
else
balance.herbs = false
end
cecho("stage3")
end
I'm using a registered event handler of 'gmcp.Char.Vitals'. This worked for me in Achaea using Mudlet, and I've checked to make sure gmcp.Char.Vitals.herb is a valid references in Aetolia. I put in error checks in the form of echoes, but the script doesn't function at all. Not even at 'stage 1'. This is also the exact error I get in the Lua console:
[ERROR:] object: (event handler function) function:(Status)(attempt to call a nil value)
*replaced HTML tags in the error.
Can anyone help?
0
Comments
Oh lol, looks like the 1 in gmcp is a string. Awkward.
If anyone else has this problem, replace the gmcp.Char.Vitals.thing == 1 with gmcp.Char.Vitals.thing == "1".
Entropy Curing System for Mudlet - FREE!
function get_stats()
if not gmcp.Char or not gmcp.Char.Status then
return e.echo("Awaiting a GMCP status packet.")
end
local stats = {
"unread_msgs",
"guild",
"explorer",
"class",
"unread_news",
"bank",
"order",
"race",
"name",
"gold",
"status",
"level",
"city",
"fullname"
}
-- This block just captures any changes in value and runs the ui:update_status_bar() function if a change is detected.
for _, key in ipairs(stats) do
if o.stats.last[key] ~= o.stats[key] then
ui:update_status_bar()
end
o.stats.last[key] = o.stats[key]
end
-- This literally just iterates over the stats table and downloads each key.
for _, key in ipairs(stats) do
o.stats[key] = gmcp.Char.Status[key]
end
-- This is just a quick, lazy add-on I did to make sure 'class' and 'status' are always lower case, and 'vampire' just returns 'undead.'
o.stats.class = o.stats.class:lower()
o.stats.status = o.stats.status:lower():gsub("vampire", "undead")
end
the way she tells me I'm hers and she is mine
open hand or closed fist would be fine
blood as rare and sweet as cherry wine
This basic system has GMCP handling through events @Radakail, I could explain it but this will let you look at the code for it
http://forums.aetolia.com/discussion/932/basic-mudlet-starter-system
to see where you went wrong / right ..
but you have to name the script ' CharVitals '
and its
function CharVitals( event ) not, CharVitals(event,args)
and this, vitals = gmcp.Char.Vitals
really unsure what you trying to do here.. but cant do that in mudlet only in cmud if im correct on what your trying.
Like i said, that link has a small starter script in mudlet and has it all in, take a look at it @Radakail it might make more sense then us describing it on here
debug.getinfo(foo).source