Quick Coding Questions

VayneVayne Rhode Island
Thought I'd make a thread for quick coding question!

My Questions: I'm trying to make a alias for throwing phials looking something like this ^en (n|s|e|w|ne|nw|se|sw|u|d|in|out)$ or ^en something that matches those or nothing at all$

in order to execute a script that if matches[2] == nil(is that the right thing to put?) then it throws at the ground else it throw it in whatever direction.

How do I get the alias to match the direction or nothing at all?
image
«13456724

Comments

  • I would do ^en(?: (n|s|e|w|ne|nw|se|sw|u|d|in|out))?$

    (?:stuff)? matches 0 or 1 "stuff" and the ?: prevents it from being captured.
  • edited January 2015
    You can then have, in the substitution:

    send("throw endorphin at " .. (matches[2] or "ground"))

    I think.  Going by what @Klendathu‌ said.
  • Adet said:
    You can then have, in the substitution:

    send("throw endorphin at " .. (matches[2] or "ground"))

    I think.  Going by what @Klendathu‌ said.
    Should be:

    send("throw endorphin " .. (matches[2] or "at ground"))
  • edited January 2015
    In order to make farming Xhaiden easier, I tried making this trigger:



    It gets thwarted, however, when this happens (my prompt getting in the way and being on the same line):


    So how can I fix this/make a working trigger?

    It should be pretty clear, btw, that my knowledge of coding, triggers and aliases is rudimentary at best.


  • edited January 2015
    @Asphel‌

    Here is a possible way to set it up so you do not have to work around the prompt:



    Give that a whirl!

    You can make the (.*) part more specific once you know that much works.


    P.S. if you enjoy MushClient stick with it :)
  • Isn't this fixed by turning on ga/something conversion? It adds more new lines from what I remember but it prevents this iirc
  • I do believe it is the "Convert IAC EOR/GA to new line" setting.

    If you wanted to try this It would be under Game > Configure > Output and it should be the last check box on the right of that dialog window.

    Might change how things are currently setup though for @Asphel‌.
  • edited January 2015
    Mudlet

    I'm trying to build on @Taurnil‌'s very helpful humour tracker, using lines from EVALUATE HUMOURS as an update to target humour levels, within a multi-line trigger.

    Currently, I have:

    ^Looking over (\w+), you see that:$ 
    ^\w+ humours are all at normal levels.$
    As a multiline/AND Trigger, line delta 1, and

    EvalTarget = matches[2]:lower()
    if EvalTarget == target then
    melcount = "0"
    sancount = "0"
    chocount = "0"
    phlcount = "0"
    end
    As the result (where melcount etc. are the variables for each individual humour level).

    The trigger fires okay, but it doesn't appear as though (\w+) is being captured as matches[2] - I've tried adding

    Eval = matches[2]
    echo(Eval)
    to the beginning of the response, and it's not giving any output.



    This is the easy trigger, as well.  My follow-up question is how I go about creating a trigger that will match:

    Looking over Tesha, you see that:
    Her phlegmatic humour has been tempered a total of 1 times.
    Her sanguine humour has been tempered a total of 1 times.
    Her choleric humour has been tempered a total of 1 times.
    Her melancholic humour has been tempered a total of 1 times.

    Where each the last four lines will only appear if that humour has been tempered, but will always occur in that order.  I haven't tried this one yet - I'm hoping I don't need to create four different triggers for it (each with a different humour line and line delta), because that seems inefficient, but that's the only way I can think of doing it currently.

    ETA: I should probably specify the client: Mudlet.  It might be obvious from the fact that I'm (failing at) using lua, but I'm not sure whether there's another client that also uses it.

    ETA(again): I know that \w+ is a very lazy way to match his/her - I'm currently working on basics, though.
  • If you use a multiline/AND trigger the matches are stored in the multimatches table instead. The first index is the line in the trigger, the second works the same way as the matches table. So you'd want multimatches[1][2] for the name in that first trigger.
  • edited January 2015
    Do you really need to worry about the order? How about...

    ^H(?:is|er) (\w+) humour has been tempered a total of (\d+) times\.$
    The ?: should mean "do not capture". If it doesn't work just increment all the matches[X] by one.

    Then you can either change it to a table and do
    humours[matches[2]]=matches[3]
     or keep it as-is and do
    if matches[2]=="melancholic" then
       melcount = matches[3]
    elseif matches[2]=="sanguine" then sancount = matches[3] elseif matches[2]=="phlegmatic" then phlcount = matches[3] elseif matches[2]=="choleric" then chocount = matches[3] end
    Change to multimatches[][] if you want the target checking.

    EDIT: This won't clear a humour that reaches 0 and is no longer listed, so you'll need something for that. Maybe a separate trigger on the Looking over X line that runs first and clears them all?
  • edited January 2015
    @Fendo, those parentheses in your regex aren't doing anything.
  • And you definitely want to write something without a .* at the beginning whenever it is at all possible to do so - that's not just an issue of specificity, it's an issue of performance. Whenver you start a regex with ".*", the regex engine will have to backtrack through every single letter in every single line the game sends you.

    If you wanted to capture that prompt, you could write:

    ^(?:\d+h, \d+m \w*-)?You pull a green leaf from the bush\.$
  • @Tael‌

    My bad with the parenthesis, just is something I pull from Mudlet. I Learned something new with that.

    As I stated in my original post, they could get more specific once they know the first part works.

    When they stated coding experience is rudimentary at best, I was going with the broad strokes and then you work at getting more specific, at least that is how I have always seen it to  learn. To each their own though.
  • edited January 2015
    Just to clarify: The parentheses do the same thing in Mudlet and in MushClient. It's a pretty common mistake people make while learning regex to think you have to have parentheses around every wildcard (the "match any character" period for instance), but parentheses have nothing to do with wildcards. Putting parentheses around something doesn't actually affect matching at all - it just indicates to the regex engine that you want to save that part of the match because you're going to use it for something later. (To be picky, you can use them for grouping things you want to quantify too, like I did in the regex above, but mostly they're for defining capture groups. And when you use them just for grouping, you put a ?: at the beginning to tell the regex engine not to capture the group contents.)

    So \d+h matches "one or more (the +) numbers (the \d) and then the letter h". But let's say you wanted to make a trigger to see if that number was lower than 80% of your max health so you could sip health whenever that happened - you need some way to reference the number in your script - that's where the parentheses come in. So instead of \d+h you do (\d+)h which means "one or more numbers, and save that part, then the letter h". And then your client has some way to reference the "capture group" - in mudlet this is matches[2] (matches[1] is always the entire matching line) and in the HTML5 client this is args[1] - I don't know what it is in MushClient.

    As for the rudimentary regex with the .* at the beginning, what I was trying to get across is that it actually won't work if you have enough of those triggers and/or you're on a slow computer. If the prompt can show up before any line, you would presumably be putting that in every trigger and with enough of them, you'd start seeing lag from your scripts. In most cases, you're fine to use something less-specific and stick a .* in, but a .* at the beginning of a regex is a special case that's particularly bad for performance thanks to the way regex engines work.
  • In Mushclient it's "%1", "%2" etc., with "%0" being the entire matching line. Yes, they're always strings, but it's simple enough to convert back from numbers. It also means you can for example Send("kick %1"). If you want to use more than 9 wildcards you need to wrap it in <>, e.g. "kick %<10>" so it reads in both digits. You can also name wildcards in the match line then refer to them by that name, but I've honestly never needed it.

    That's assuming it's in the script for the trigger itself. If you're using the automatically-call-a-function part of the trigger box it's a little different, and I suggest anyone doing so check out the (quite useful!) documentation here.
  • Teynanin said:
    In Mushclient it's "%1", "%2" etc., with "%0" being the entire matching line. Yes, they're always strings, but it's simple enough to convert back from numbers. It also means you can for example Send("kick %1"). If you want to use more than 9 wildcards you need to wrap it in <>, e.g. "kick %<10>" so it reads in both digits. You can also name wildcards in the match line then refer to them by that name, but I've honestly never needed it.

    That's assuming it's in the script for the trigger itself. If you're using the automatically-call-a-function part of the trigger box it's a little different, and I suggest anyone doing so check out the (quite useful!) documentation here.
    Slight correction there - they're never strings in and of themselves unless the match contains quotes, they literally get placed into the script as-is. The quotes around them make them strings. So a = %1 would do a = 5, where a = "%1" would do a = "5".
    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.
  • SkyeSkye The Duchess Bellatere
    Mudlet

    Ohai gais. Okay I've got these two scripts. First one is for a small miniconsole to which I echo most things I need to pay attention to. I'm not too good at catching scrolling text anymore, but a box near my commandline is great for making me take notice of things. What it does is it actually pushes my display output a few pixels upwards to make space for a the miniconsole (AKA 'alerts') below. It also makes use of the sysWindowResizeEvent Event handler.
    setBorderBottom(71)
    setBorderLeft(3)
    bottom_border = Geyser.Container:new({
      name = "bottom_border",  
      x="0.5%", y="94%",       
      width = 500, height="10%",
    })

    alerts = Geyser.MiniConsole:new({
      name="alerts",
      x= "0%", y= "0%",
      width="70c", height="4c",
    }, bottom_border)
    alerts:setColor(205,197,191,50)
    alerts:setTextFormat(205,197,191,0,104,139,1,0,0)
    alerts:setFontSize(12)
    alerts:setWrap(80)

    The second is the code for repositioning SVO's single command prompt to accomodate the 'alerts' box:
    function svo.bottomprompt:reposition()
    
    local width,height = calcFontSize(svo.conf.singlepromptsize or 10) local x,y,w,h = self:get_x(), self:get_y(), self:get_width(), self:get_height() moveWindow(self.name, self:get_x()+3, self:get_y()-53-(height+(height/3))) resizeWindow(self.name, self:get_width(), self:get_height())
    end

    Ordinarily both codes work perfectly fine on their own. Both the 'alerts' box and repositioned single prompt are sitting where they should when I start mudlet. But for some weird reason, the display settings (as configured by setBorderBottom/Left) refuse to be processed unless I go to my scripts and save 'alerts'. That's all I need to do. It's not exactly a hassle or anything, I'm just wondering why it keeps doing that. 



  • KlendathuKlendathu Eye of the Storm
    I'm guessing, but it could be because you're specifying a percentage, but it doesn't know the percentage of what. You need to tell it the screen height and width.

    WindowWidth, WindowHeight = getMainWindowSize();

    Tharos, the Announcer of Delos shouts, "It's near the end of the egghunt and I still haven't figured out how to pronounce Clean-dat-hoo."
  • while the script registers to the sysWindowResizeEventHandler, I see no function in the "alerts" script. Create a new script "alertResizeEventHandler", register the sysWindowResizeEventHandler and add the following function in the script:
    function alertResizeEventHandler()
      setBorderBottom(71)
      setBorderLeft(3)
    end
  • SkyeSkye The Duchess Bellatere
    Yeah that fixed it :) thanks!


  • I have a problem with Mudlet multi line trigger.

    I have a trigger for dstab to be used for affliction tracking: two venom lines and then the  dstab line.
    If it rebounds, then it shouldn't process the venoms. But if instead of rebounding if I get the prompt back it means that there was no rebounding and I should process the venoms

    I've uploaded a few screenshots to display how I've set up the trigger, and the end result:
    https://imgur.com/a/8Ur2X

    This almost works perfectly except that it gets fired twice. Anyone know how to fix this?
  • AustereAustere Tennessee
    edited January 2015
    Kimby said:
    I have a problem with Mudlet multi line trigger.

    I have a trigger for dstab to be used for affliction tracking: two venom lines and then the  dstab line.
    If it rebounds, then it shouldn't process the venoms. But if instead of rebounding if I get the prompt back it means that there was no rebounding and I should process the venoms

    I've uploaded a few screenshots to display how I've set up the trigger, and the end result:
    https://imgur.com/a/8Ur2X

    This almost works perfectly except that it gets fired twice. Anyone know how to fix this?
    I trigger my dstab to capture the weapon/venom at the point of envenom.  When I attack, it adds the weapon to a table and enables two sets of triggers: dodge/rebounding/reflection which removes the captured weapon from the table, and prompt which processes the table of weapons by what is envenoned/disables the two triggers. While your way is going to look prettier, mine was the only way I could figure out how to process multiple weapon attacks carrying multiple venoms at once[Dsl] so I just transposed it to dstab as well. As long as you don't make a logic error in the prompt trigger (so you know it always closes itself), I think it should be good. . Not fully tested, though. 

    If that makes no sense, I can post mine up tonight to show you. I added a little blue dot echo to the end of the trigger so I know it isn't staying open. Using this method, you can even add in checks to make sure you actually sent the attack,  as an illusion fail safe. 

    Edit: if you use serverside alias, and include illusion, the illusion line will fire before the prompt, so you might want to add that into your prompt trigger as well.  It looks like you are just leaving your trigger open too long, though. . I dunno,  someone surely has a better method. I just needed dsl, rend, dstab, and single stabs to all work off one trigger. 
  • AustereAustere Tennessee
    edited January 2015
    Nevermind this one! 
  • Kimby said:
    I have a problem with Mudlet multi line trigger.

    I have a trigger for dstab to be used for affliction tracking: two venom lines and then the  dstab line.
    If it rebounds, then it shouldn't process the venoms. But if instead of rebounding if I get the prompt back it means that there was no rebounding and I should process the venoms

    I've uploaded a few screenshots to display how I've set up the trigger, and the end result:
    https://imgur.com/a/8Ur2X

    This almost works perfectly except that it gets fired twice. Anyone know how to fix this?
    It looks to me like you want to add a line spacer between the two venom lines. By default, a multimatch trigger can match multiple patterns on the same line, as long as they're in order. In your case, that means that the trigger will be satisfied by 

    You rub some curare on a needle-pointed dirk.
    You rub some kalmia on a needle-pointed dirk.
    You prick Cobault twice in rapid succession with your dirk.

    as intended, but it will also be satisfied by just 
    You rub some kalmia on a needle-pointed dirk.
    You prick Cobault twice in rapid succession with your dirk.
    In the second case, multimatches[1] and multimatches[2] should both be {"You rub some kalmia on a needle-pointed dirk.","kalmia"}, so I would expect it to run once and set your tracking variable to {"curare","kalmia"}, then a second time and set it to {"kalmia","kalmia"}, or maybe vice versa (not sure what order they'll be processed in). It looks from your prompt like they might actually be getting set to {"curare","curare"}, which I don't understand, but there might be something else weird going on.

    In any case, if you add an extra pattern in between the two venom patterns, with type "line spacer", it will force the venom patterns to match on separate lines, which, if I'm correct, should solve the problem with it firing twice. You'll then want multimatches[3][2] for the second venom.

  • Thanks Eld! I'm going to try this later today.
    And thank you Austere too!
  • AustereAustere Tennessee
    @Eld‌ the man. I am sitting over here still using expandAlias and telling @Kross‌ that if you use \d, it returns a number and you don't have to format it.  Probably best to take all of my coding advice as the ramblings of a mad man. 





    Sorry again, Kross.
  • @Eld it works! Thanks so much :)
  • edited June 2015
    function changedRoom()
     currentroom = gmcp.Room.Info.num
     if currentroom == oldroom then
      return false  
     else
      return true
     end
    end



    What's the best way to capture my previous/old room to feed into this function? I basically want to keep track of when I've moved rooms but I don't want it to get lost whenever gmcp.Room.Info updates without me actually moving rooms.
    Thanks.
  • edited June 2015
    It looks like you're trying to use a function when what you really want is an event handler. That is to say, you don't want to just define something to do, you want to do something when a specific thing happens. Think of it like a trigger for GMCP.

    You need to make a function that runs on the GMCP Room.Info event - this is pretty easy to do in Mudlet. Have a look at the Triggering on GMCP section here: http://www.mudlet.org/wp-content/uploads/2013/02/GMCPtutorial.pdf

    Your event function will look something like this.
    function my_room_function()
        if gmcp.Room.Info.num ~= currentRoom then
        lastRoom = currentRoom
        currentRoom = gmcp.Room.Info.num
    end end
    That will save your last room and your current room. If you want to do something when you change rooms, just put the function calls for whatever you want to do under currentRoom = gmcp.Room.Info.num, inside that if block.
Sign In or Register to comment.