Announcement

Collapse
No announcement yet.

How to use "IF" control structure for 2 actions?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use "IF" control structure for 2 actions?

    As it mentioned in Help, If structure works several ways.
    Code:
    if condition then
    do something here end
    What I want is if condition met then do one thing and do another thing.

    For Example:
    Code:
    if(SerialNumberScreen.AttemptCount >= SerialNumberScreen.MaxAttempts) then
    Application.Exit(0);
    File.OpenURL("WebsiteURL", SW_SHOWNORMAL);
    end
    In above example, if user failed to entered correct serial key & reaches max attempts then application exit and visit to a website/url.
    But my code is not working, tried adding "and" but no luck.

  • #2
    Originally posted by admirable View Post
    For Example:
    Code:
    if(SerialNumberScreen.AttemptCount >= SerialNumberScreen.MaxAttempts) then
    Application.Exit(0);
    File.OpenURL("WebsiteURL", SW_SHOWNORMAL);
    end
    In above example, if user failed to entered correct serial key & reaches max attempts then application exit and visit to a website/url.
    But my code is not working, tried adding "and" but no luck.
    What you see is expected. You are ending the script before the File.OpenURL() is executed. If you want to perform an action, this action must happen BEFORE any Application.Exit(), Application.ExitScript(), Screen.Jump() / Back / Next / End, or even a "return".

    Ulrich

    Comment


    • #3
      Originally posted by Ulrich View Post

      What you see is expected. You are ending the script before the File.OpenURL() is executed. If you want to perform an action, this action must happen BEFORE any Application.Exit(), Application.ExitScript(), Screen.Jump() / Back / Next / End, or even a "return".

      Ulrich
      Oh my gosh. How silly am I!
      Thanks for the help.

      Comment


      • #4
        Additionally, you can use Lua's pseudo-ternary statement. This can give strange results in the case where you use boolean operators incorrectly but otherwise it's a very sound way of getting a single-line, if-then statement.

        Code:
        local bIsCool = true; --change this to false to alter the ternary result
        
        local sCool = (bIsCool) and "I'm cool!" or "Nope, I'm not cool...";
        
        Dialog.Message("Are you cool?", sCool.);
        https://github.com/CentauriSoldier

        Comment

        Working...
        X