Results 1 to 9 of 9

Thread: Short-circuit evaluation?

  1. #1
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default Short-circuit evaluation?

    Does Simba allow for Short-circuit evaluation?
    http://en.m.wikipedia.org/wiki/Short-circuit_evaluation

    Example 1:
    Simba Code:
    if (actionbar.getAdrenalinePercent() = 100) and (berserkTimer.getTime() > 60000) then
            begin
              sendKeys('b', 200, 40);
              berserkTimer.start();
              healthTimer.start();
              exit;
            end;

    If I put the timer check before the adrenenaline check, and the timer check results false, will the script still check the adrenbar%?[/QUOTE]

    Example 2:
    Would this:
    Simba Code:
    function areaCheck(): boolean;
    begin
      if length(ogl.getModels(403123861, mainScreen.getBounds())) or length(ogl.getModels(584121683, mainScreen.getBounds())) then
        exit(true);
    end;
    Be the exact same as this:
    Simba Code:
    function areaCheck(): boolean;
    begin
      if length(ogl.getModels(403123861, mainScreen.getBounds())) then
        exit(true);
      if length(ogl.getModels(584121683, mainScreen.getBounds())) then
        exit(true);
    end;

  2. #2
    Join Date
    Mar 2014
    Posts
    205
    Mentioned
    4 Post(s)
    Quoted
    116 Post(s)

    Default

    Code:
    program new;
    
    function checkOne(): boolean;
    begin
      Writeln('One');
      exit(false);
    end;
    
    function checkTwo(): boolean;
    begin
      Writeln('Two');
      exit(true);
    end;
    
    
    begin
      if(checkOne() and checkTwo()) then
        Writeln('Three');
    end.
    Short answer; yes.

  3. #3
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Quote Originally Posted by adc View Post
    Code:
    program new;
    
    function checkOne(): boolean;
    begin
      Writeln('One');
      exit(false);
    end;
    
    function checkTwo(): boolean;
    begin
      Writeln('Two');
      exit(true);
    end;
    
    
    begin
      if(checkOne() and checkTwo()) then
        Writeln('Three');
    end.
    Short answer; yes.
    I'm sure you mean no, because it does check the second statement:
    Simba Code:
    program new;

    function checkOne(): boolean;
    begin
      Writeln('One');
      exit(false);
    end;

    function checkTwo(): boolean;
    begin
      Writeln('Two');
      exit(true);
    end;


    begin
      if(checkOne() or checkTwo()) then
        Writeln('Three');
    end.

  4. #4
    Join Date
    Mar 2014
    Posts
    205
    Mentioned
    4 Post(s)
    Quoted
    116 Post(s)

    Default

    You're using "or" there. checkOne() returns false, and thus it checks checkTwo(), which returns true, resulting in all three outputs. In my post, I used "and", which causes it to only output "One", as checkOne() returns false. If you change checkOne() to return true, it only prints "One Three", as checkTwo() is not checked.

    @lovebotter, because I forgot to quote you.

  5. #5
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Quote Originally Posted by adc View Post
    You're using "or" there. checkOne() returns false, and thus it checks checkTwo(), which returns true, resulting in all three outputs. In my post, I used "and", which causes it to only output "One", as checkOne() returns false. If you change checkOne() to return true, it only prints "One Three", as checkTwo() is not checked.

    @lovebotter, because I forgot to quote you.
    Oops, my bad, didn't see the first one to be false I assumed you had them both on true!
    Thanks

  6. #6
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    In lape you can turn it on or off by putting {$B+} or {$B-} at the top of your script.
    Working on: Tithe Farmer

  7. #7
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    In lape you can turn it on or off by putting {$B+} or {$B-} at the top of your script.

    And default is on?
    Could save me some resources if I change a few around assuming timers are least processing intensive.

  8. #8
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by lovebotter View Post
    And default is on?
    Could save me some resources if I change a few around assuming timers are least processing intensive.
    Why would a timer be process intensive?

  9. #9
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Quote Originally Posted by tls View Post
    Why would a timer be process intensive?
    They aren't but neither are some other functions.
    Was just saying I should then change a few conditionals around based on least intensive, relatively. Mainly timers or small booleans first.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •