Mudlet for Noobs

Quick question (I hope)

In my trigger field I have: 
^There is a door in the way, to the (.+)$

In the big box below, I have: 

door_shut = matches[2]

send("open door " ..door_shut)


But it's not firing when I run into a closed door. Can someone help me learn?

«1

Comments

  • You can make it.

    ^There is a door in the way, to the (\w+)$
  • You're missing the period at the end of your regex

    ^There is a door in the way, to the (\w+)\.$
    image
  • Thank you both!
  • TharvisTharvis The Land of Beer and Chocolate!
    I do think the period is actually important there, as if it's not stated in the trigger line, the (\w+) will also capture the period, and I'm not very soon if when you type for example "Open door North." it works. could be wrong though!
    Aurora says, "Tharvis, why are you always breaking things?!"
    Artemis says, "You are so high maintenance, Tharvis, gosh."
    Tecton says, "It's still your fault, Tharvis."

  • Tharvis said:
    I do think the period is actually important there, as if it's not stated in the trigger line, the (\w+) will also capture the period, and I'm not very soon if when you type for example "Open door North." it works. could be wrong though!
    \w won't catch a period. If you made it ^There is a door in the way, to the (\w+)$, it wouldn't match at all.
  • TharvisTharvis The Land of Beer and Chocolate!
    oh? You learn something new every day!
    Aurora says, "Tharvis, why are you always breaking things?!"
    Artemis says, "You are so high maintenance, Tharvis, gosh."
    Tecton says, "It's still your fault, Tharvis."

  • JonathinJonathin Retired in a hole.
    \w only matches non-whitespace alphanumeric characters.
    I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.
  • Jonathin said:
    \w only matches non-whitespace alphanumeric characters.
    And underscore.
  • edited March 2014
    Eld said:
    Jonathin said:
    \w only matches non-whitespace alphanumeric characters.
    And underscore.
    \w is shorthand for [A-Za-z0-9_]
    \s for [ \t\f]
    \d for [0-9]

    capital is reverse

    \D is [^0-9] or [^\d]
    \W is [^\w]
    \S is [^\s]

    edit: be careful of doubling up reverses.

    [^\d\s] is anything not a number or whitespace
    [\D\S] is anything not a number OR not whitespace (which, since they don't overlap and both exclude anything, mean that is the same as a period - everything)
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
  • edited March 2014
    This seems like a good place to pose a Mudlet question! What would the regex be for the following?

    Oaken vial165951              a renewal balm           138       120

    I'm trying to match it so it captures only 'vialxxxx' 'a renewal balm' '138' and '120'. I want to account for and exclude the spaces, but because the words I want to capture are numerous, if I use (.*) or (.+) it captures the spaces, \s+ doesn't differentiate from (.*) for spaces and so they still get captured if I use \s+ and the only other regex patterns I know are for single words only. It needs to also work for variations such as:

    Oaken vial37312               a tonic of mentality     134       146


    Thank you!

    tagging skilled mudlet-ers
  • First I'd use elist2, so the first column doesn't contain spaces.

    Second you can make the regex for the second column non-greedy by appending a ? to the quantifier. All in all, your regex could look like this:
    ^(\w+)\s+(.+?)\s+(\d+)\s+(\d+)$
  • My version is 
    ^Vial(\d+)\s+(\D+?)\s{2,}(\d+)\s+(\d+)$

    Mostly the same as @Keneanung's, except that it captures just the vial number instead of "Vial1234", and a couple of the other specifiers are slightly more specific (but not in a way that's likely to affect anything here).
  • Here's another one. I'd like to sent up an alias to search the readlog of an organization

    it triggers on ^rlog (.*)

    and in the big box, I have: 

    local org1 = matches[2]

    local org2 = matches[3]

    local org3 = matches[4]

    send("readlog " ..org1 ..org2 ..org3)


    but it never works

  • You're only getting 1 matches[2] from your one bracket - try doing:

    ^rlog (\w+) (\w+) (\w+)$
  • Very close, now it sends but without a space in between the variables. 

    So I tried 
    send("readlog " ..org1 " " ..org2 " " ..org3 " " ..org4)

    but it didn't work
  • @Sorrow You need to use the concatenation operator (..) on either side of all the parts, so send("readlog " .. org1 .. " " .. org2 .. " " .. org3)
  • Thank you both!

  • How do I remove a specific value from a table, if I don't know which position in the table it is? For example, let's say I had a table likeso: 

    testTable = { "Person1", "Person2", "Person3", "Person4" }

    and I want to remove "Person2" from the table. Now, this might be the initial state of the table, but soon enough Person2 would be inserted into the end (fourth) position of the table, and Person3 would be moved into the second position of the table and so on, so I can't really predict where in the table everyone is at any point in time (Apart from initialization). 

    I could only find documentation on removing things from a table based on their position rather than actual value. 

  • If you're sure the entries are going to be unique, you can get the position with table.index_of:
        local pos = table.index_of(testTable, "Person3")
        table.remove(testTable,pos)

    If "Person3" occurs twice, I believe this will just remove the first instance. If there are duplicates, I think something like this should work:

        for i=#testTable,1,-1 do
            if testTable[i]=="Person3" then table.remove(testTable,i) end
        end

    The idea there is to iterate in reverse so that you don't miss any instances because of the reindexing that table.remove does. Always makes me a little nervous to change a table I'm iterating over like that, but I think that version's safe. Someone else might have a better idea.

  • Yeah, use table.index_of to find the position out. You can even chain them if you're confident the value is there: table.remove(testTable, table.index_of(testTable, "myvalue"))
  • For an experiment with striking, I want to make a table that functions similarly to a last-in-first-out 'stack', where I can push striking attack locations (neck, shoulder, etc), and once I do a slash/strike attack, the first value is popped to serve as the striking attack. When I do the next combo, the next last stacked attack is popped, and so on and so forth.

    What's a good way to do that in mudlet? Or is there a better way to do that for BMs?

  • Google "lua lifo", you'd get your answers on that one.
  • I just use 

    table.insert(table, thing, 1)

    and

    table.remove(table, 1)

    Achieved dragon on the 13th of Aeguary, 634 - aged 21 and 1 month and 21 days.

    Elder dragon on the 6th of Chronos 635 - aged 22 and 8 months and 14 days.
  • JonathinJonathin Retired in a hole.
    edited March 2014
    That's still first-in-first-out though, where the first thing you enter is the first thing sent out.

    He wants last-in-first-out, where the last thing he entered is the first thing he sent out.

    ETA: actually, sounds like he wants it to alternate between them or something.

    I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.
  • Adding the value at index 1 will move everything down, so then just calling the first value will be the last entered thing. Removing the value from index 1 using table.remove will move everything up an index so it will be last in first out. I think anyway.

    I wouldn't of thought it would be the best way to queue striking though, because you have to think backwards which is an irritation with venoms that you get to avoid being a blademaster, but each to their own.
  • Jonathin said:
    That's still first-in-first-out though, where the first thing you enter is the first thing sent out.

    He wants last-in-first-out, where the last thing he entered is the first thing he sent out.

    ETA: actually, sounds like he wants it to alternate between them or something.

    No, what @Cathy said is lifo. It always inserts at the front of the list, and pops from the front as well.
  • JonathinJonathin Retired in a hole.
    oh, derp. Yeah. I derped.
    I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.
  • Hm, actually @Accipiter is somewhat right. I think I was stuck thinking in a venoms-user way. First-in-first-out would be a better approach, but would I have to think about moving all the contents up when I 'pop' a value in a FIFO 'stack'(is it still called a stack in this case, or is there another programmer term for it?), or are there already functions that do that?

Sign In or Register to comment.