Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Easiest way to check for multiple conditions

  • #1, by Uraal 13 years ago Zitieren
    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.
  • #2, by afrlme 13 years ago Zitieren
    are we talking Lua here or if else queries done via the editor?
  • #3, by Uraal 13 years ago Zitieren
    Done via editor smile
  • #4, by afrlme 13 years ago Zitieren
    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.
  • #5, by Uraal 13 years ago Zitieren
    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 ^^ )
  • #6, by afrlme 13 years ago Zitieren
    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".
  • #7, by Uraal 13 years ago Zitieren
    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!