Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

IF/THENs will be my doom

RobbRobb Member Posts: 3
I'm positive that there must be something silly I'm not seeing, but I haven't found it yet and it's really bothering me.

if (mystance == "Rizet" or "Gyanis" or "none") then

send("combo trip lowhook lowhook "..target)

elseif (mystance == "Ein-Fasit" or "Laesan" or "Vae-Sant") then

send("combo lowhook trip lowhook" ..target)

end


I've got a few aliases that are similar to this one that aren't behaving the way I want them to.  Basically they're just firing the first "send" when mystance == one of the stances following the "elseif"


I am definitely a novice in LUA, but I feel like I've been learning alot and this is frustrating me to no end.

Comments

  • MathiausMathiaus PennsylvaniaMember Posts: 1,019 ✭✭✭✭
    Someone explained to me once that 'or' works as separate clauses, meaning you have to do mystance == "Rizet" or mystance == "Gyanis" or mystance == "none". There is probably a better way, but that's the only thing I've found so far.
    image
  • IluvIluv Member Posts: 703 ✭✭✭✭
    Probably a smarter way to do this but try

    if (mystance == "Rizet") or (mystance ==  "Gyanis") or (mystance == "none") then
    image
  • RobbRobb Member Posts: 3
    May not be pretty, but it works and that's what counts.  Thanks a ton!
  • CassiusCassius Member, Beta Testers Posts: 607 ✭✭✭
    Alternatively with a table if you prefer: aTable = {"rizet","gyanis","none"} if table.contains(aTable,mystance) then
  • KhizanKhizan Member Posts: 2,648 ✭✭✭✭✭
    edited March 2014

    Those answers are correct. This is why they are correct. Note, I'm not a LUA person, but this answer should be accurate nonetheless.

    Two things you need to know here:

    1. The value "0" is regarded as 'FALSE' and anything that is not a zero is regarded as 'TRUE'.  
    2. The "OR" operator separates test conditions, not the parameters of test conditions. If any single test condition evaluates true, the entire OR statement is true

    With that in mind let's say that you're in Vae-Sant when you run the "if (mystance == "Rizet" or "Gyanis" or "none")" check. This statement will be checked against the three following conditions:

    1. mystance == "Rizet"
    2. "Gyanis"
    3. "none"

    It evaluates the conditions as follows:

    1. the test (mystance == "Rizet") evaluates to 0, so this is FALSE.
    2. "Gyanis" is not 0 so this is TRUE.
    3. "none" is not 0 so this is TRUE.

    Since at least one test condition in the OR statement is true, the entire thing evaluates to true and it takes the "then" and not the "else". As written, that statement will ALWAYS evaluate to true and the "elseif" will NEVER be reached.

    The corrected if statement "if ( (mystance == "Rizet") or (mystance == "Gyanis") or (mystance == "none") )", on the other hand, evaluates the following conditions:

    1. mystance == "Rizet"
    2. mystance == "Gyanis"
    3. mystance == "none"

    If the value is Vae-Sant, it should evaluate those conditions as FALSEFALSEFALSE and it will skip the "then" and move into the "else".


    "On the battlefield I am a god. I love war. The steel, the smell, the corpses. I wish there were more. On the first day I drove the Northmen back alone at the ford. Alone! On the second I carried the bridge! Me! Yesterday I climbed the Heroes! I love war! I… I wish it wasn’t over."

    Iniar
  • IniarIniar AustraliaMember Posts: 3,213 ✭✭✭✭✭

    in Lua, 0 is true. Only 'false' and uninstantiated variables are 'false'.

    wit beyond measure is a Sidhe's greatest treasure
  • KhizanKhizan Member Posts: 2,648 ✭✭✭✭✭

    That is the most ****-backwards horrible thing. :(



    "On the battlefield I am a god. I love war. The steel, the smell, the corpses. I wish there were more. On the first day I drove the Northmen back alone at the ford. Alone! On the second I carried the bridge! Me! Yesterday I climbed the Heroes! I love war! I… I wish it wasn’t over."

    IniarAzefelSeptus
  • MathiausMathiaus PennsylvaniaMember Posts: 1,019 ✭✭✭✭
    Khizan said:

    That is the most ****-backwards horrible thing. :(



    Nexus was like this too unfortunately.
    image
  • KhizanKhizan Member Posts: 2,648 ✭✭✭✭✭
    With that said, if you go back through my post and replace every '0' or 'zero' with a 'false', it should still all be accurate.

    "On the battlefield I am a god. I love war. The steel, the smell, the corpses. I wish there were more. On the first day I drove the Northmen back alone at the ford. Alone! On the second I carried the bridge! Me! Yesterday I climbed the Heroes! I love war! I… I wish it wasn’t over."

    Iniar
  • JuranJuran OhioMember Posts: 909 ✭✭✭✭✭
    Khizan said:

    That is the most ****-backwards horrible thing. :(

    Nil is also false, for what that's worth.

    More than 0 being true, what really screwed me up when I first started using Lua is that empty strings ("") are also true. The only data types that return false are 'nil' and 'false'.
    Iniar
  • FyraineFyraine Member Posts: 23

    A bit late, but I thought I'd give you an example of how to do this without if/then at all:



    stanceTable = stanceTable or {} stanceTable.trip_lowhook = { ["Ein-Fasit"] = "lowhook trip lowhook", ["Laesan"] = "lowhook trip lowhook", ["Vae-Sant"] = "lowhook trip lowhook", Ryzet = "trip lowhook lowhook", Gyanis = "trip lowhook lowhook", none = "trip lowhook lowhook", } -- ^ In your scripts, make a table like that for each attack combo type, in this example I assume it is something you do when you want to prone someone. -- Then in your aliases/macros/attack functions: send( "combo " .. stanceTable.trip_lowhook[ mystance ] .. " " .. target )
  • GabrielGabriel Fort Valley, Georgia USMember Posts: 89 ✭✭
    edited March 2014
    Ok, getting into if/then today.

    I've got macros that enter:
    combatattack = afflict
    or:
    combatattack = damage

    Then, I've got an alias with this:

    if (combatattack == "afflict") then expandAlias("aff")

    elseif (combatattack == "damage") then expandalias("dmg") end


    When I use that alias it does squat. It's not showing errors. It just does... nothing.


    I know the aff and dmg aliases work correctly so the issue isn't there.

    image
  • MereisMereis Member Posts: 229 ✭✭✭
    edited March 2014
    Try
    combatattack = ("damage")
    combatattack = ("afflict")

    EDIT:

    I think the explanation here is that if you do it straight-out combatattack = damage, combatattack is equating itself to a variable called damage, rather than the text "damage", which is what your if-then statement is using to determine whether to use alias "aff" or alias "dmg".
    currently tentatively active
    (may vanish for periods of time)
    Gabriel
  • GabrielGabriel Fort Valley, Georgia USMember Posts: 89 ✭✭
    Thanks,
    I made the change and it fires off the aff alias so that's progress. However, when I use the macro to change: combatattack = ("damage"), it continues to fire the aff alias rather than the dmg alias.


    image
  • FyraineFyraine Member Posts: 23
    combatattack = "damage"
    combatattack = "afflict"


    display(combatattack)
    if combatattack == "damage" then expandAlias("dmg")
    elseif combatattack == "afflict" then expandAlias("aff")
    else cecho("\n<sienna>  No pvp mode selected.")
    end


    First, get rid of the unnecessary stuff, like the (round brackets).
    Then check very carefully for typos or missing "quotes" where they are needed.
    If it still doesn't work, put temporary test echoes into it (like the display(combatattack) line, which you should delete after it is working.)
    Gabriel
  • GabrielGabriel Fort Valley, Georgia USMember Posts: 89 ✭✭
    Perfect. Thank you.
    image
Sign In or Register to comment.