Looking for more active discussion? Join our Discord at https://discord.gg/x2s7fY6

Mudlet Coding Questions

edited October 2014 in Tech Talk
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?

Comments

  • edited October 2014
    Just got the echoes working, but for some reason balance.herbs remains false... despite gmcp.Char.Vitals.herb being 1.

    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".
    Ashmer
  • ElyniElyni New Zealand
    Did you initialise the 'balance' table?
  • AshmerAshmer Barefoot Adventurer Life
    Just as a note, a really easy way to capture stuff like this is something like this:

    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

    Ishin
  • Radakail said:


    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:


    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 ..
    Mudlet Bashing System for sale. Message if interested
  • I used event handlers in the script to begin with. The problem was GMCP in Aetolia utilising strings for their Boolean states of 1/0. I commented after my initial post on how to deal with that. Took a while of angry error checking to figure it out.
    Ashmer
  • take a look at the above script on how he did it.

    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
    Mudlet Bashing System for sale. Message if interested
  • Someone asked me if there was a way to look at the code in a function without having to pull up the editor. Figured I'd share it. debug.getinfo(foo).source
    Nebeu
Sign In or Register to comment.