Skip to content

Question from a begginer scripter

I know this is simple, but I've been teaching myself scripting and cant seem to get it correct. I want a trigger to fire a certain command if a variable equals a certain string. What I'm doing now is making myself auto-swim back the way I came if I get pulled in while fishing. I know how to do it if the variable matches a number, that is with the ==, but how does one get a conditional statement to be true when the variable matches a string? for instance

if fishdir = e or east then swim w

that's obviously not the correct syntax but I'm just trying to clarify what I'm trying to do in the simplest terms.

Comments

  • if apple == "green" then send("eat apple") end

    In the case of Mudlet. Though having mass stops you from being pulled along while fishing I think.

  • aha! So I need to put it in quotes. There we go. Thanks, Kryss! :P
  • I have another question!! This time about multi-line triggers.

    How does one get something to happen, when ONE line of a multi-line trigger is there and another is not? As in a bait check after a failed hook. I have something set up to probe my pole after every failed attempt to hook, and I have the last two lines of the pole description (Bears the mark of, this pole is baited with) now how do I get myself to re-bait if the second line is not there? Do I need to do something else and not use a multi-line trigger?
  • edited September 2013
    To also clarify, if you're checking a single variable against two things, you still have to reference that variable twice.

    This line is wrong:
    if fishdir=="e" or "east" then

    It is wrong, because what it means is "if fishdir is equal to e, or if east". Since "east" isn't false, that line will always be true. The correct way to do the conditional is:

    if fishdir=="e" or fishdir=="east" then

    EDIT: And even that is ambiguous to read. It will work, because of order of operations (== is evaluated before or), but just reading it with your eyes it's not entirely clear what parts are executed when. For readability's sake, I'd write it as

    if ((fishdir=="e") or (fishdir=="east")) then
    I am the righteous one... 
    the claims are stated - it's the world I've created 
  • Lionas said:
    To also clarify, if you're checking a single variable against two things, you still have to reference that variable twice.

    This line is wrong:
    if fishdir=="e" or "east" then

    It is wrong, because what it means is "if fishdir is equal to e, or if east". Since "east" isn't false, that line will always be true. The correct way to do the conditional is:

    if fishdir=="e" or fishdir=="east" then

    EDIT: And even that is ambiguous to read. It will work, because of order of operations (== is evaluated before or), but just reading it with your eyes it's not entirely clear what parts are executed when. For readability's sake, I'd write it as

    if ((fishdir=="e") or (fishdir=="east")) then

    thanks, but I already figured this out well enough for my own purposes, heh. My second question is giving me a headache now, about the conditional trigger.
    Desmond said:
    I have another question!! This time about multi-line triggers.

    How does one get something to happen, when ONE line of a multi-line trigger is there and another is not? As in a bait check after a failed hook. I have something set up to probe my pole after every failed attempt to hook, and I have the last two lines of the pole description (Bears the mark of, this pole is baited with) now how do I get myself to re-bait if the second line is not there? Do I need to do something else and not use a multi-line trigger?
    any idea what to do in this scenario?
  • I don't use mudlet, and haven't in a very long time. In CMUD I'd make a withinlines trigger, but I don't think that's an option in mudlet, so instead I'd do something with multiple triggers, like this:

    it bears the mark of - it has the mark I care about, yay! --- set a flag indicating that I'm checking for bait

    trigger for line two - it's baited, unset the flag

    trigger for prompt - If I'm still checking for bait, that means the bait line never showed up, so I need to reel, bait, cast
    I am the righteous one... 
    the claims are stated - it's the world I've created 
  • MathiausMathiaus Pennsylvania
    Have an alias do:

    send("probe pole")
    bait = false

    When it checks, you'll see if you have it or not, and have the bait line send:

    bait = true

    Then have you're prompt right after the bait check line have:

    if not bait then
    send("bait pole with whatever")
    bait = true
    end
    image
  • Probably better, cuts out one of the intermediate triggers.
    I am the righteous one... 
    the claims are stated - it's the world I've created 
  • I dunno how to set my prompt as a trigger :/
  • edited September 2013
    Just like any other trigger. I'd use perl regex.

    EDIT:
    Here's mine, converted from CMUD pattern matching to regex
    ^<(\d+)/(\d+)h\(\d+\) (\d+)/(\d+)m\(\d+\) (.*)x <([e-])([b-])>(?: (<.*>)?) (\d+)E (\d+)b$

    My prompt looks like this:
    <550/550h(100) 488/490m(99) 70.13x <eb> <db> 78E 0b
    I am the righteous one... 
    the claims are stated - it's the world I've created 
  • In Mudlet you can use the pattern "return isPrompt()" and set the type to "Lua function". That'd match any prompt, whatever it looks like.
  • thanks, Akumu! I ended up setting the bait check to that line you get when nothing is happening, you know the 'Your line floats motionless' one, but I think I'll change it. That is, if my script doesn't get deemed too automated.
  • IniarIniar Australia
    edited September 2013
    Desmond said:
    thanks, Akumu! I ended up setting the bait check to that line you get when nothing is happening, you know the 'Your line floats motionless' one, but I think I'll change it. That is, if my script doesn't get deemed too automated.
    E: statement retracted.
    wit beyond measure is a Sidhe's greatest treasure
Sign In or Register to comment.