Easiest way to check for multiple conditions

  • #1, by UraalTuesday, 09. July 2013, 15:20 7 years ago
    Is there some way to check for multiple conditions at once? I wish to see if all levers are in correct positions and only then execute victory animations. For example:

    If "condition 1" is true & "condition 2" is true too
    then

    else

    1
    2
    3
    4
    5
    6


    I have tried putting if sentences inside each other like this

    If "condition 1" is true
    If "condition 2" is true
    Play Awesome animations
    else
    else
    1
    2
    3
    4
    5
    6


    I have a faint idea that this might have to do something with me not understanding what is the difference between "else" and "end if" and in the way they work.

    Incase you decide to help me, thanks in advance.

    Newbie

    93 Posts


  • #2, by afrlmeTuesday, 09. July 2013, 15:25 7 years ago
    are we talking Lua here or if else queries done via the editor?

    Imperator

    6842 Posts

  • #3, by UraalTuesday, 09. July 2013, 15:26 7 years ago
    Done via editor smile

    Newbie

    93 Posts

  • #4, by afrlmeTuesday, 09. July 2013, 15:39 7 years ago
    hmm...
    ok dokie.

    You can create multiple IF whatever in a single query.

    if condition "one" is true
    if condition "two" is true
    if condition "three" if false
    ...
    do something
    else
    do something else
    endif
    endif
    endif
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11


    same amount of endif as if!

    I prefer Lua because it's easier to write out & you can have as many queries as you like in a single sentence with only 1 if.
    also we can create complex queries thanks to the "and" & "or" functions smile

    if cond1 and cond2 and cond3 and not cond4 then
    -- do something!
    elseif cond4 then
    -- do something else
    end
    1
    2
    3
    4
    5
    6


    notice the not before cond4... this turns it into negative value (checks if cond4 is false)
    you can also use: if cond1 == true and cond4 == false etc.

    Imperator

    6842 Posts

  • #5, by UraalTuesday, 09. July 2013, 15:47 7 years ago
    Absolutely brilliant, thank you a lot!

    I still don't quite understand exactly what "endif" does codewise in comparison to "else". Understanding it would allow me more flexibility with using it ... ? (pretty please ^^ )

    Newbie

    93 Posts

  • #6, by afrlmeTuesday, 09. July 2013, 16:27 7 years ago
    endif is used to close the if queries.

    for instance you can have multiple queries inside of a single if or inside of an action...

    if condition x is true
    if condition a is true then do something endif
    if condition b is true then do something endif
    else -- this is for doing something else if condition x is false
    do something else...
    endif
    1
    2
    3
    4
    5
    6
    7


    if condition a then
    do something
    endif

    if condition b then
    do something
    else
    do something else
    endif
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10


    in Lua: we can use "else" or "elseif" ...
    elseif is better because we only need to close with one end rather than one for each if.
    in the editor we only have "else".

    Imperator

    6842 Posts

  • #7, by UraalThursday, 11. July 2013, 16:50 7 years ago
    Awesome stuff AFRLme, learning new stuff with Visionaire even 1,5 years since I started the project. Getting there, slowly, but getting there. Cheers once again!

    Newbie

    93 Posts

Write post