Skip to content

Mudlet Scripting

17810121318

Comments

  • I changed the script to

    function queueSet(action,type)

    --Sets the action as the "active" in the queue type. Type is bal, eqbal, or eq.

    sys.queue[type].command = action

    cecho("Debug:"..sys.queue.eqbal.command)

    end


    and the debug changed to


    Alias name=run lua code(^lua (.*)$) matched.

    Alias: capture group #1 = <lua queueSet(test,eqbal)>

    Alias: capture group #2 = <queueSet(test,eqbal)>

    LUA: ERROR running script run lua code (Alias6) ERROR:[string "--Queue..."]:73: attempt to index 

    field '?' (a nil value)n



  • And I just did a super simple version - 

    function queueSet(action,type)

    --Sets the action as the "active" in the queue type. Type is bal, eqbal, or eq.

    cecho("T1")

    cecho("Type:"..type)

    cecho("Action:"..action)

    end


    and Mudlet thinks that type doesn't exist


    LUA: ERROR running script run lua code (Alias6) ERROR:[string "--Queue..."]:73: attempt to 

    concatenate local 'type' (a nil value)

  • IniarIniar Australia
    What are you passing as your second argument? queueSet("get gold","eqbal")?
    wit beyond measure is a Sidhe's greatest treasure
  • I think I've got it fixed. Quotation marks OP
  • Sounds like your input is bad.

    Should be something like:
    lua queueSet("test","equal")
  • IniarIniar Australia
    edited December 2014
    For the narcissist in you:

    This little script allows you to sub using your own color 'names':

    sub = function(input,options)

    if clean.sub then

    if not input then

    deleteLine()

    return

    end

    local arg = input

    arg = "<"..clean.base..">"..arg

    arg = arg:gsub("<stop>","<"..clean.base..">")


    for match in string.gmatch(arg,"%<[_%w]+%>") do

    local m = match

    m = m:gsub("<","")

    m = m:gsub(">","")

    if clean.custom[m] then

    -- <"..r..","..g..","..b..":0,0,0>

    arg = arg:gsub(match,"<"..table.concat(clean.custom[m],",")..":0,0,0>")

    elseif color_table[m] then

    arg = arg:gsub(match,"<"..table.concat(color_table[m],",")..":0,0,0>")

    end

    end


    if not options or not options.no_new_line then arg = "\n"..arg end

    if not options or not options.no_delete_line then deleteLine() end

    decho(arg)

    end

    end


    clean.base = "dim_grey"

    clean.custom = {

    -- <"..r..","..g..","..b..":0,0,0>

    ["blood"] = { 141,38,77 }, -- maroon, 176, 48, 96

    ["cadet_dark"] = { 76,126,126 }, -- cadet blue, 95, 158, 160

    ["deep_orange"] = { 240,110,20 }, -- orange, 255, 140, 0

    ["my_violet_red"] = { 135,78,103 }, -- pale_violet_red, 219, 112, 147

    }

    clean.sub = true

    Allows me to do things like:

    sub("<cadet_dark>"..matches[2].." <stop>(<deep_orange>"..matches[3].."<stop>)",{no_new_line=true})

    wit beyond measure is a Sidhe's greatest treasure
  • IniarIniar Australia
    edited December 2014
    For my deeply narcissistic self.
    -(anti-weapon field).
    I dsl'd a decadent goblin priest. (a curved sabre) -133 ( 0.70)
    I dsl'd a decadent goblin priest. (a curved sabre) -3 ( 0.00)
    I slew a decadent goblin priest.
    wit beyond measure is a Sidhe's greatest treasure
  • What do the <> and [[]] symbols mean? My cursory le Googles aren't finding any documentation.
  • IniarIniar Australia
    <> is interpreted by both cecho and decho
    a double [[ means a string literal
    while a [] in a table refers to a key;
    my_table["key"] is the equivalent of my_table.key BUT
    local key = "hello"
    my_table[key] is equivalent to my_table.hello
    wit beyond measure is a Sidhe's greatest treasure
  • Not really a question, but a TIL: If you use an echo to test your MiniConsole wrap length, don't use one big word, or you'll wonder why it's broken for a week or three.
  • edited December 2014
    I'm trying to track shadowplants on multiple targets, because because. 

    2nd match is the herb, 3rd match is the name. herb is set and accounted for. Need the name in the timer ID so I can hearken back to it when I need to kill the deactivate timer, so I tried to do what I found at http://www.lua.org/pil/14.1.html to utter failure. Dunno why I bothered to try doing the fancy code for the activate timer, but I did.

    timer1 = _G[matches[3].."-shadowplant-activate"]

    timer2 = _G[matches[3].."-shadowplant-deactivate"]


    timer1 = tempTimer(1,[[trackerAdd(]]..matches[3]..[[,"shadowplant-"]]..herb..[[)]])


    timer2 = tempTimer(4,[[trackerRemove(]]..matches[3]..[[,"shadowplant-"]]..herb..[[)]])



    Help me to unfrak this, please?


    Edit: Already fixed the wrong match in the temp timers >.> Had it fixed in the main copy, but missed the switch here.

  • Try:

    timer1 = tempTimer(1, function () trackerAdd(matches[3], "shadowplant-" .. herb) end)
    and
    timer2 = tempTimer(4, function () trackerRemove(matches[3], "shadowplant-" .. herb) end)

    I think [[]] prevents variable expansion or something, so I tend to use function () <blah> end instead. Works out most of the time for me.
    image
  • edited December 2014
    I'm getting "lua syntax error: 1" and "lua syntax error: 4". I threw in cecho(timer1) after the first pair of variable sets, and it's reporting the variable as nil.

    Edit: Okay, so the assignment thing does not do at all what I thought it did. I'll debug some more to see if I can go from there, but I have the timers at least trying to go.

    Edit 2 - Got it working. My [[]] craziness didn't work either, so the function thing is much cleaner. Will have to remember that for some future stuff. 

    Final version - 

    timer1 = matches[3].."-shadowplant-activate"

    timer2 = matches[3].."-shadowplant-deactivate"


    timer1 = tempTimer(1, function () trackerAdd(name, "shadowplant-" .. herb) end)


    timer2 = tempTimer(4, function () trackerRemove(name, "shadowplant-"..herb.."") end)

  • Is there any frickin way to make control+c copy something in Mudlet?
  • MathiausMathiaus Pennsylvania
    If it's not set as something else, it should. Once you highlight something, you have the option of ctrl c or left clicking to copy as normal or html
    image
  • edited December 2014
    Be careful how you select though. If I accidentally select in the timestamp instead of over the actual text, or in a different miniconsole and move into the primary one, Mudlet tends to crash on me. Also, it adds newlines when you copy/paste multiple lines, which just show up as spaces when you paste. I also tend to have better results using right click+copy instead of control+c, which likes to grab my command line instead of what I've got selected. And I think right click+copy is the only way to reliably copy from other consoles, like from chat window.

    A reliable copy through selecting the left margin is about the only thing I miss about Cmud.
    image
  • For some of the reasons @Dicene mentioned is why I put most of my major lua scripts in external files. Then load them as part of my init by doing

    dofile(getMudletHomeDir().."/scripts/MyScript.lua") where getMudletHomeDir() is (at least on a mac) ~/.config/mudlet/profiles/<your profile>/


    That way I can check all my major scripts into version control and use whatever editor I want to do the actual coding. Because lets be honest; mudlet is a good client but fails as an editor.

    image
  • edited December 2014
    Dicene said:
    And I think right click+copy is the only way to reliably copy from other consoles, like from chat window.
    That's what I meant. Copypasting the wrong sections of my chat capture is aggravating. I thought maybe there'd be some way to make ctrl+c a key that copies whatever's highlighted.
  • IniarIniar Australia
    Kabaal said:
    I'm trying to track shadowplants on multiple targets, because because. 

    2nd match is the herb, 3rd match is the name. herb is set and accounted for. Need the name in the timer ID so I can hearken back to it when I need to kill the deactivate timer, so I tried to do what I found at http://www.lua.org/pil/14.1.html to utter failure. Dunno why I bothered to try doing the fancy code for the activate timer, but I did.

    timer1 = _G[matches[3].."-shadowplant-activate"]

    timer2 = _G[matches[3].."-shadowplant-deactivate"]


    timer1 = tempTimer(1,[[trackerAdd(]]..matches[3]..[[,"shadowplant-"]]..herb..[[)]])


    timer2 = tempTimer(4,[[trackerRemove(]]..matches[3]..[[,"shadowplant-"]]..herb..[[)]])



    Help me to unfrak this, please?


    Edit: Already fixed the wrong match in the temp timers >.> Had it fixed in the main copy, but missed the switch here.

    I'm surprised the _G thing didn't work.

    Here's how the string-literal would be written:
    [[display("]]..herb..[[")]] => kelp
    [[display("shadowplant-'..]]..herb..[[']]) => shadowplant-kelp

    I always avoid using 
    [[display("]]..matches[2]..[[")]] => the matches table always gets rewritten, so it is highly unreliable.

    As Dicene puts it, it's always cleaner and nicer to use function() end where possible.
    wit beyond measure is a Sidhe's greatest treasure
  • Does the io stuff need the file to already exist? If so, do you just have to manually install the file or is there some way to make sure it goes along with the script?
  • IniarIniar Australia
    You can get Lua to create the file by doing something called assert. I believe when you assert a writable or appendable file, it creates a new one, but I have yet to sort out how to make it fail grace-fully. @Dicene?
    wit beyond measure is a Sidhe's greatest treasure
  • It looks like if you use io.open in write mode it will create the file if it doesn't exist. io.open should return nil if there is an error so you can check that you ended up with a good file before you start writing. http://stackoverflow.com/questions/7277388/creating-new-files-with-lua-i-o-functions http://stackoverflow.com/questions/6889589/create-a-new-file-in-lua-luafilesystem http://www.tutorialspoint.com/lua/lua_file_io.htm
    image
  • First thing: Anyone made use of the db functions at all? I'm rather unfamiliar with sql, but my players table is sitting at 2300 entries right now and even though reading from the table is quick, writing to the table from a Truehonours has become really slow. If using DB instead of a standard table would be more efficient, I'd definitely be willing to learn.

    Second thing: Has anyone added a regex library to the Lua included in Mudlet? I really want access to regex in scripts, but I don't particularly look forward to trying to compile a lua regex library and integrate it properly, since I usually find a way to mess those things up.
    image
  • IniarIniar Australia
    Nope and nope. Interested in what people have/will learn though.
    wit beyond measure is a Sidhe's greatest treasure
  • I use the mudlet db functions in a few places, and they seem fine. They give you control over most things you will want (sorting, WHERE type filtering, etc). You don't really need to know sql to use them unless you want to get into some complicated queries.

    I don't currently don't have any tables that size so I can't speak to the functions performance from experience, but I would imagine it depends on where your performance hit is happening. Is it the parsing of the truehonours? The lookups? The actual writes? If it is the parsing then using a database probably won't help much. If it is the lookups and writes using a database could give a performance boost depending on your implementation (if you have to do a bunch of complicated queries for each item before you write it there might not be much of a gain). Sorry none of that really helps much but like most topics involving performance it depends a lot on your use case.

    I haven't tried to add a regex library to lua, but doesn't it already have one? I was pretty sure string.match would accept regex.

    As an aside, I was under the impression mudlet just included a standard lua interpreter with some custom functions[1]. At one point I even pulled down the source code,  extracted the functions and added them to my local lua path so I could do some scripting and debugging outside of mudlet.

    image
  • As far as the thonours issue, I checked os.clock() repeatedly between each line of code. The issue was with me saving the file to the harddrive every time I updated the players table. Removed it and check take an average of 0.003s after ping instead of upwards of a second(2300kb file on a really terrible computer).
    image
  • Disk writes are always expensive (unless you have a SSD). With that in mind I would imagine using a db would give you a nice boost to performance. There are some functions available too that would allow you to unpack your table right into your new sheets (the mudlet documentation calls them sheets, really they are tables but they didn't want lua tables and sql tables getting mixed up) after a small conversion.
    image
  • edited December 2014
    Can someone once and for all help me understand why sometimes, you escape the period at the end of a sentence with \  but other times, especially if you have a capture right at the beginning of the trigger, using \ before the period at the end of the sentence will prevent the trigger from firing.  I just don't understand how/why this is at all.  I understand that the escape makes the client interpret the . literally, and without an escape, the . just matches any single character (thanks to some careful, patient explanations), but I just absolutely don't understand why sometimes this is THE way to format the end of a regex trigger, and other times, it can keep that same trigger from firing at all.  
  • Jules said:
    Can someone once and for all help me understand why sometimes, you escape the period at the end of a sentence with \  but other times, especially if you have a capture right at the beginning of the trigger, using \ before the period at the end of the sentence will prevent the trigger from firing.  I just don't understand how/why this is at all.  I understand that the escape makes the client interpret the . literally, and without an escape, the . just matches any single character (thanks to some careful, patient explanations), but I just absolutely don't understand why sometimes this is THE way to format the end of a regex trigger, and other times, it can keep that same trigger from firing at all.  

    I pretty much always escape it, otherwise it acts as a wildcard.
  • That makes perfect sense... So, this is what I'd like to finally understand.  

    This trigger works:  ^(\w+)\'s aura of weapons rebounding disappears.$

    This one does not:  ^(\w+)\'s aura of weapons rebounding disappears\.$

    I really feel I've seen this before, and my guess/intuition is that it has something to do with capturing stuff right after the newline thing.  It's the kind of thing that drives someone not immersed in coding (me) absolutely nuts.  
Sign In or Register to comment.