Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Mudlet Scripting

18911131418

Comments

  • MathiausMathiaus Member Posts: 1,039 ✭✭✭✭
    I wouldn't escape ' in the first place. I really can't think of a reason why you would escape it before the 's' there.
    image
  • JulesJules Member Posts: 1,080 ✭✭✭
    And now either one works... Gah.  
  • SeptusSeptus Member, Beta Testers Posts: 781 ✭✭✭✭✭
    Its good practice to always escape the period, if you only want a period. Not really relevant in the case of your trigger (since that line only ever ends in one), but in other cases where the final punctuation mark is variable, it can be pretty relevant.
  • CassiusCassius Member, Beta Testers Posts: 607 ✭✭✭
    Septus said:

    Its good practice to always escape the period, if you only want a period. Not really relevant in the case of your trigger (since that line only ever ends in one), but in other cases where the final punctuation mark is variable, it can be pretty relevant.

    I try to remove as many wild cards and open ended matches as I can in my regex. Not sure the end improvement on performance but I tend to think that's good practice.

    That being said, if you don't enjoy coding, do whatever makes it work for you and move on.
  • JulesJules Member Posts: 1,080 ✭✭✭
    I want to enjoy it... but I want it to make sense to me :(
  • KabaalKabaal Member Posts: 303 ✭✭✭
    I hate RegEx. So!


    ^List of all rooms in (.+) \(areaid (\w+) - (\w+) rooms\):$

    versus

    List of all rooms in the City of Stavenn (areaid 151 - 369 rooms):

    Gave me a match, but no joy when in Mudlet.

    I'm also trying unsuccessfully at all to match

       168: An empty cobblestone path.
    Those messages. My current is

    ^\s+(\w+):  (.+)\.


    /me showers everyone with cookies.
  • UltrixUltrix Member Posts: 288 ✭✭✭
    edited January 2015
    Kabaal said:

       168: An empty cobblestone path.

    think you could do this instead:  ^(\d+): (.*)\.$

    (yes i know the ' (.*)' is somewhat superfluous as .* will capture spaces, but it makes it easier to read in my head)

    Kabaal said:
    List of all rooms in the City of Stavenn (areaid 151 - 369 rooms):
    ^List of all rooms in (.*) \(areaid (\d+) \- (\d+) rooms\)\:$   (you need to escape the '-')
  • KabaalKabaal Member Posts: 303 ✭✭✭
    It matches when I do an echo of that phrase, but not when I just pull it from the mapper by doing the ROOM LIST (blah) :(
  • DiceneDicene Member Posts: 913 ✭✭✭✭
    From Mudlet Mapper? It's cause (I think) most normal echo things aren't parsed by triggers.
    image
  • KabaalKabaal Member Posts: 303 ✭✭✭
    Dicene said:
    From Mudlet Mapper? It's cause (I think) most normal echo things aren't parsed by triggers.
    Alright then. I think I'll just Frankenstein the echoRoomList code for my purposes, then. Trigger would've been easier :(
  • KabaalKabaal Member Posts: 303 ✭✭✭
    Today in things Kabaal did wrong:

    table = {thing1 = thing2} 

    is not equivalent to

    table[thing1] = thing2

    Especially with regards to a pairs(table) call.

  • DiceneDicene Member Posts: 913 ✭✭✭✭
    edited January 2015
    Uh. So Mudlet exposes the PCRE portion of Lrexlib 2.7.2 through _G.rex
    I'm glad I managed to find that before attempting to compile and add it myself.

    Example usage:

    local re, r

    local lastTime = os.clock()


    re = rex.new([[^(?<name>\w+) balls up one fist and hammerfists (?<target>\w+)\.$]])

    print("\nExecuting re 10000 times....")


    for i = 1, 10000, 1 do

      r = {re:exec("Septus balls up one fist and hammerfists you.")}

    end


    print(os.clock() - lastTime, "\n")

    display(r)


    Output(on my extremely slow computer):


    Executing re 10000 times....    

    0.065999999998894    

        

    {

      1,

      45,

      {

        1,

        6,

        42,

        44,

        name = "Septus",

        target = "you"

      }

    }

    image
  • GeneveGeneve Member Posts: 15 ✭✭
    Ok, I want to gag a specific line without the empty prompt lines firing.

    deleteLine() deletes the line itself, but the prompt still fires. Is there any way to remove that as well?
  • KabaalKabaal Member Posts: 303 ✭✭✭
    edited January 2015
    Make a multiline trigger. 

    First pattern is the line (so exact match, perl, whatever)

    Second line is a lua function with the pattern as: 
    return isPrompt()

    Click the multiline/AND box, change the delta to 3
    Edit: The delta can be 1. Mistake saved for posterity.
    In the script, do

    deleteLine()

    moveCursor(0,getLineNumber()-1)

    deleteLine()

  • CassiusCassius Member, Beta Testers Posts: 607 ✭✭✭
    edited January 2015
    There is also a native Mudlet function that @Dicene‌ stumbled across that deletes the current line and any prompt following it. The name escapes me so maybe he can chime in.

    Edit: http://wiki.mudlet.org/w/DeleteFull
  • UltrixUltrix Member Posts: 288 ✭✭✭
    Kabaal said:
    Make a multiline trigger. 

    First pattern is the line (so exact match, perl, whatever)

    Second line is a lua function with the pattern as: 
    return isPrompt()

    Click the multiline/AND box, change the delta to 3
    Edit: The delta can be 1. Mistake saved for posterity.
    In the script, do

    deleteLine()

    moveCursor(0,getLineNumber()-1)

    deleteLine()

    Just as a note on moveCursor() -- it's noted here that moveCursor moves relative to your Mudlet screen and therefore if you have Mudlet wrapping your text (which most of us probably do), it will not actually delete the full line if the line is wrapped.
  • IyrandarIyrandar Member Posts: 11
    How would you go about having a stance tracker to be visibly seen in your prompt? I have the trigger line thanks to @Ultrix and I can send an echo, but configuring it I am at a loss.
  • IniarIniar Member Posts: 3,213 ✭✭✭✭✭
    When you echo on the 'return is prompt()' trigger, doesn't that append it to your prompt?
    wit beyond measure is a Sidhe's greatest treasure
  • DiceneDicene Member Posts: 913 ✭✭✭✭
    edited January 2015
    Assuming your stance is in a variable called predStance(although I like sticking things in namespaces, so I'd have it in me.predStance):

    Say the Stance change message were: You flow smoothly into the <blah> stance.

    Stance Change Trigger
    Pattern(regex): ^You flow smoothly into the (\w+) stance\.$

    Script:
    predStance = matches[2]

    Prompt Trigger
    Pattern(Lua function): return isPrompt()

    Super simple script:
    echo(" " .. predStance)

    Slightly more advanced script for a nicer look(also won't generate errors before you've seen a stance change:

    local str = " <white>["

    predStance = predStance or "none"


    if predStance=="Gyanis" then

    str = str .. "<goldenrod>Gya"

    elseif predStance=="Vae-sant" then

    str = str .. "<deep_sky_blue>Vae"

    elseif predStance=="Rizet" then

    str = str .. "<deep_pink>Riz"

    elseif predStance=="Ein-fasit" then

    str = str .. "<SaddleBrown>Ein"

    elseif predStance=="Laesan" then

    str = str .. "<CadetBlue>Lae"

    else

    str = str .. "   "

    end

    str = str .. "<white>]"


    cecho(str)


    Here's an example of what the more advanced form of the second trigger looks like:
    image

    Disclaimer: I don't have a Pred anymore, so I don't know if Vae-sant and Ein-fasit are listed with a lowercase or uppercase first letter to the second part of their hyphenated name. If the first letter there is uppercase, you'd have to fix that in my script to get it to work properly. Also, there's a good chance I've got the trigger for the stance change wrong, so update with whatever Ultrix gave you.
    image
  • IyrandarIyrandar Member Posts: 11
    Thanks @Dicene for your input and that code. It's awesome and works out great.
  • DiceneDicene Member Posts: 913 ✭✭✭✭
    edited January 2015
    Stumbled unto this and figured it might be of use to someone, especially while Mudlet still doesn't support 256 colors in color triggers, just ansi.

    If you use very specific value and check lines with something like selectString(line) getFgColor(), you should be able to match these and capture to something like Demonnic's chat window with ease.

    http://upload.wikimedia.org/wikipedia/en/1/15/Xterm_256color_chart.svg
    image
    image
  • KabaalKabaal Member Posts: 303 ✭✭✭
    Not finished, and you can't just plug n play the script and have it work. These are all the functions my tracker uses. This was one of my first projects when starting back and learning Mudlet, so ignore stuff like me using table.getn(table) instead of #table :3
    Hopefully, it'll at least be an example of what to (not) do


    And here is my database of things. Again, not finished, and it was done before I knew about the #table thing :(



  • IyrandarIyrandar Member Posts: 11
    Next thing to work on towards understanding combat and PK is more tracker stuff in particular the aliases.

    So I have trigger msgs for things like rebounding and shield and parryinng, and I'm guessing those msgs are the 'trackers'. Now, I need to harness that trigger msg into an alias and execute multiple commands based off the tracker msg.

    For example if rebound = 1 based off the msg and shield = 1 based off its own msg as well then how do I go about setting up attacks for that circumstance or really any variety of circumstances? Such as rebound = 1 shield = 0, vice versa, rebound = 0 shield = 0, etc. This stuff confuses me and thus I seek help and better understanding on how these things work.

    "// #If (@rebounding = 1 & @shield = 1) {#if (@pstance = einfasit) {combo raze raze lowhook @target};#if (@pstance = laesan) {combo raze raze lateral @target}}.” <-- how do you translate that into mudlet?


    Thanks guys.
  • KabaalKabaal Member Posts: 303 ✭✭✭
    edited February 2015
    if rebounding == 1 and shield == 1 then 
          if pstance == "einfasit" then
                 send("combo raze raze lowhook "..target)
         elseif pstance == "laesan" then
                 send("combo raze raze lateral "..target)
          end
    end


    Key things to note:
    1. In the ifs, you need to use ==, not =
    2. The .. is the concatenation syntax, which basically means it puts strings together.
    3. Strings have to be denoted by ""s.
    4. Variables are called with just the name
    5. Steps 2-4 are used in the send() function calls to SEND (ha!) the string to the main window.
    6. Lua functions work more like %functions in CMud than the # functions, but you don't have to use special symbols for them either way.
     
  • IyrandarIyrandar Member Posts: 11
    How would I continue that code for the next set of circumstances be it rebound = 0 and shield = 0, rebound = 0 and shield = 0? Use 'elseif' then have commands under those variables?
  • DiceneDicene Member Posts: 913 ✭✭✭✭
    edited February 2015
    I'd advise using true and false instead of 1 and 0.

    If rebounding is going up, use:
      rebounding = true

    If rebounding is going down, use:
      rebounding = false

    Then in your IF statements, you replace "rebounding == 1" with "rebounding" and replace "rebounding == 0" with "not rebounding".

    Obviously not required, but I find that kind of code more readable in the end, and it's probably best practice to use booleans instead of integers whenever possible. =P

    Then, to fill out the rest of that conditional tree:

    if rebounding and shield then  --matches when they have BOTH rebounding and shield
      if pstance=="einfasit" then
        send(blah)
      elseif pstance=="laesan" then
        send(blah)
      end
    elseif rebounding or shield then --matches when they have either of the two(would also match both if this wasn't an elseif of that original condition)
      if pstance=="einfasit" then
        send(blah)
      elseif pstance=="laesan" then
        send(blah)
      end
    else --this condition will only fire if they have neither rebounding nor shield
      if pstance=="einfasit" then
        send(blah)
      elseif pstance=="laesan" then
        send(blah)
      end
    end
    image
  • MathiausMathiaus Member Posts: 1,039 ✭✭✭✭
    edited February 2015
    #If (@rebounding = 1 & @shield = 1) {#if (@pstance = einfasit) {combo raze raze lowhook @target};#if (@pstance = laesan) {combo raze raze lateral @target}}

    Equals to:

    if rebounding == true and shield == true then
               if pstance == "einfasit" then send("combo raze raze lowhook "..target)
               elseif pstance == "laesan" then send("combo raze raze lateral "..target)
               end

    elseif rebounding == false and shield == false then
               <more_coding>
    end

        segments can be either 'rebounding == true' or 'rebounding', and     segments can be 'rebounding == false' or 'not rebounding'.

         segments show when checking if a variable matches a certain word(string), you need to use quotations(") on each side to show that is a word, not another variable being compared.

       
    shows you how to call your variables. Two periods(..) call it, then two after escape it. If the variable is being called at the beginning or end of the section, you don't need the two periods, such as: (target.." is here"), ("I see "..target), and it would normally be: ("There is "..target.." at my location.)

    Dicene pretty much told you it. I felt like colour coding it for you for fun anyways.
    image
  • RascaRasca Member Posts: 124 ✭✭✭
    Question: Is there a good way to embed a .GIF inline within the scrollback, or else draw it in a separate UI element for X seconds and then clear it?

    Also, is the best practices for playing audio just using the audio trigger functionality in the GUI mentioned here?
    無駄だ!無駄無駄無駄無駄無駄無駄無駄無駄無駄無駄無駄無駄!ザ・ワールド!時よ止まれ!くらえ!そして、時は動き出す。
    image
  • RylaeisRylaeis Member Posts: 33 ✭✭
    edited March 2015
    1) Don't think Mudlet supports .gif images, at least that's what Vadi said on the mudlet forums. (he's the main scripter for it now)

    2) AFAIK, yes. I think you can also use playSoundFile() or something like that. Not mucked around with it too much, myself.

    image
  • DiceneDicene Member Posts: 913 ✭✭✭✭
    I don't think playSoundFile or the sound option in triggers is working at all in Mudlet 3.0, just so you know.
    image
Sign In or Register to comment.