Easiest way to check for multiple conditions

  • #1, z UraalTuesday, 09. July 2013, 15:20 hodinky 12 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
    
    


    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
    


    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.

    Bažant

    93 Posts


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

    Imperátor

    7285 Posts

  • #3, z UraalTuesday, 09. July 2013, 15:26 hodinky 12 years ago
    Done via editor smile

    Bažant

    93 Posts

  • #4, z afrlmeTuesday, 09. July 2013, 15:39 hodinky 12 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
    


    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
    


    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.

    Imperátor

    7285 Posts

  • #5, z UraalTuesday, 09. July 2013, 15:47 hodinky 12 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 ^^ )

    Bažant

    93 Posts

  • #6, z afrlmeTuesday, 09. July 2013, 16:27 hodinky 12 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
    


    if condition a then
     do something
    endif
    
    if condition b then
     do something
    else
     do something else
    endif
    


    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".

    Imperátor

    7285 Posts

  • #7, z UraalThursday, 11. July 2013, 16:50 hodinky 12 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!

    Bažant

    93 Posts