Nested IFs and Operators



  • I noticed that I couldn't use a nested IF in OB
    For example
    IF "<SOURCE>" Contains "1"
    IF "<SOURCE>" Contains "2"
    SET STATUS SUCCESS
    ENDIF
    ENDIF

    So I tried using AND operator see if it works (I tried & and &&)
    IF "<SOURCE>" Contains "1" && "<SOURCE>" Contains "2"
    SET STATUS SUCCESS
    ENDIF

    But that did not work either. Is there a way to do either of these yet?


  • Admin

    Hey, LoliScript is a very simple language that I made to expand the capabilities of OB (blocks are executed sequentially, with LS you can use IF/ELSE and WHILE). In order to write a fully fledged language I would've needed to make parsing trees for the custom language etc. which is a lot of work.

    I will explain what the parser does when it encounters an IF or an ELSE:

    IF:

    • true: keep reading
    • false: jump to the first instruction after the first ELSE or ENDIF you find (so those instructions are not executed, but the ones after them are executed)

    ELSE:

    • always jump to the first instruction after the first ENDIF you find

    To achieve IF (this && that) you can simply write

    IF condition1
    IF condition2
    ...
    ENDIF
    

    If any of those 2 IFs fail, it will jump to the ENDIF, so it will only execute them in case both are true.

    If you want to achieve IF (this || that) you can use the JUMP statement and 2 labels.

    IF condition1
    JUMP #OK
    ENDIF
    
    IF condition2
    JUMP #OK
    ENDIF
    
    JUMP #PAST
    
    #OK
    here type the instructions you wanna execute if any of the conditions is true
    
    #PAST
    this will be executed if both conditions are false or if the part above has finished
    

    I hope you understand.

    If people really want to be able to use && and || I will try to expand the parser to make it work with a linear set of conditions (no brackets).



  • The simplest way would be for you to use IronPython.
    Instead of using LoliScript to do the checking, use Python.


  • Admin

    Ironpython adds unnecessary overhead though. It would be best to use loliscript as it's faster.


Log in to reply