Results 1 to 7 of 7

Thread: What's Wrong With My 'If, Then, Else' Statements?

  1. #1
    Join Date
    Apr 2017
    Posts
    31
    Mentioned
    0 Post(s)
    Quoted
    18 Post(s)

    Default What's Wrong With My 'If, Then, Else' Statements?

    The script compiles and runs, but does not execute the else statement

    HTML Code:
    program Prophit;
     var
     x, y: Integer
    
    begin
      FindColor(x, y,211426,60,72,1128,690);
      if x>150 then
      Movemouse(x, y);
      sleep(2000);
      clickmouse(x,y,1);
      clickmouse(x,y,1);
      Writeln(x);
      Writeln(y);
      sleep(1000);
      PressKey(113);
      Movemouse(x, y);
      sleep(2000);
      Writeln(x);
      Writeln(y);
      sleep(1000);
      ShowMessage ('Press YES when prompted to install Drivers. PRESS OK OR ENTER NOW TO CONTINUE');
      sleep(2000);
      FindColor(x, y,32768,60,72,1128,690);
      Movemouse(x,y);
      Clickmouse(x,y,1);
      Clickmouse(x,y,1);
      else
      ShowMessage('Could not find icons');
    end.
    Any idea how I could get the 'Icons not found' message to appear when it doesn't find the color? At the moment it still runs the script as if it has found the colors. Cheers!
    Last edited by Fidget; 11-16-2017 at 11:03 PM.

  2. #2
    Join Date
    Apr 2017
    Posts
    31
    Mentioned
    0 Post(s)
    Quoted
    18 Post(s)

  3. #3
    Join Date
    Jan 2013
    Posts
    86
    Mentioned
    0 Post(s)
    Quoted
    25 Post(s)

    Default

    Try this, could be done better but I haven't messed with Simba in a while.

    Code:
    program Prophit;
    
    var
      x, y: Integer
    
    begin
      if (FindColor(x, y,211426,60,72,1128,690) and (x>150)) then
      begin
        Movemouse(x, y);
        sleep(2000);
        clickmouse(x,y,1);
        clickmouse(x,y,1);
        Writeln(x);
        Writeln(y);
        sleep(1000);
        PressKey(113);
        Movemouse(x, y);
        sleep(2000);
        Writeln(x);
        Writeln(y);
        sleep(1000);
        ShowMessage ('Press YES when prompted to install Drivers. PRESS OK OR ENTER NOW TO CONTINUE');
        sleep(2000);
        FindColor(x, y,32768,60,72,1128,690);
        Movemouse(x,y);
        Clickmouse(x,y,1);
        Clickmouse(x,y,1);
      end;
      if(not (FindColor(x, y,211426,60,72,1128,690) and (x>150))) then
      begin
        ShowMessage('Could not find icons');
      end;
    end.

  4. #4
    Join Date
    Apr 2017
    Posts
    31
    Mentioned
    0 Post(s)
    Quoted
    18 Post(s)

    Default

    Quote Originally Posted by deejaay View Post
    Try this, could be done better but I haven't messed with Simba in a while.

    Code:
    program Prophit;
    
    var
      x, y: Integer
    
    begin
      if (FindColor(x, y,211426,60,72,1128,690) and (x>150)) then
      begin
        Movemouse(x, y);
        sleep(2000);
        clickmouse(x,y,1);
        clickmouse(x,y,1);
        Writeln(x);
        Writeln(y);
        sleep(1000);
        PressKey(113);
        Movemouse(x, y);
        sleep(2000);
        Writeln(x);
        Writeln(y);
        sleep(1000);
        ShowMessage ('Press YES when prompted to install Drivers. PRESS OK OR ENTER NOW TO CONTINUE');
        sleep(2000);
        FindColor(x, y,32768,60,72,1128,690);
        Movemouse(x,y);
        Clickmouse(x,y,1);
        Clickmouse(x,y,1);
      end;
      if(not (FindColor(x, y,211426,60,72,1128,690) and (x>150))) then
      begin
        ShowMessage('Could not find icons');
      end;
    end.
    Amazing deejaay thank you so much.

  5. #5
    Join Date
    Sep 2014
    Location
    C:\Simba\
    Posts
    565
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    If (FindColor(x, y,211426,60,72,1128,690) and (x>150)) then
    begin
    ...
    end else
    begin
    end;

    would be better. While FindColor is a fast method, some methods aren't, and things can change. #1 it's unnecessary to perform the same operation twice, #2 things can change during the course of the operation or after it, meaning that it first may give a false value and then a true value, effectively bypassing your logic.
    Feel free to ask me any questions, I will do my best to answer them!

    Previously known as YouPee.

  6. #6
    Join Date
    May 2007
    Location
    England/Liverpool
    Posts
    1,004
    Mentioned
    9 Post(s)
    Quoted
    106 Post(s)

    Default

    I will post in much more detail later but for now I'll point out a couple things/ask why
    Why do you sleep when we have a functions created to process messages while sleeping it's called wait(???); used in the exact same way but doesn't cause the program to hang util the specified time had passed.

    Also are you sure you just want to wait what if you waited to long or what if not long enough think about all situations that could effect your script running or being stuck in a loop.

    Simba Code:
    program Prophit;

    const
    maxWait = 20000;//20 seconds

    var
      x, y, aTime,  bTime: Integer

    begin
    {old
      if (FindColor(x, y,211426,60,72,1128,690) and (x>150)) then
      begin

        Movemouse(x, y);
        sleep(2000);  //why are you waiting here for 2 seconds is there anything else you could do to tell if your ready for the next click
        clickmouse(x,y,1);
        clickmouse(x,y,1);
    }

    //new
        aTime :=  GetTickCount;
        while not FindColor(x, y,211426,60,72,1128,690) and (x>150) do  //this will be your method of choice for detecting if your ready to move on
        begin
          wait(100);
          bTime :=  GetTickCount;
          if bTime - aTime > MaxWait then TerminateScript;
          //infinite loops require failsafes incorporate one here for example use  GetTickCount and check if a certain time has passed
        end;
        Movemouse(x, y);
        clickmouse(x,y,1);
        clickmouse(x,y,1);
    //end

        Writeln(x);
        Writeln(y);
        sleep(1000); //again why are you sleeping is there anything else tobe done her instead
        PressKey(113); //is it possible to check if this event worked?
        Movemouse(x, y);
        sleep(2000); //again sleep causes hangs while using wait simba will still process event messages
        Writeln(x);
        Writeln(y);
        sleep(1000); //again
        ShowMessage ('Press YES when prompted to install Drivers. PRESS OK OR ENTER NOW TO CONTINUE');
        sleep(2000); //again
    {old
        FindColor(x, y,32768,60,72,1128,690);//this line of code is doing nothing with the infomation your asking it simply asks if the color is there and clicks regardless
        Movemouse(x,y);
        Clickmouse(x,y,1);
        Clickmouse(x,y,1);
    }

    //new
        if  FindColor(x, y,32768,60,72,1128,690)  then
        begin
          Movemouse(x,y);
          Clickmouse(x,y,1);
          Clickmouse(x,y,1);
        end else //dont rely on just one check have a failsafe a plan B so for example if not FindColor(x,y,RGB,x1,y1,x2,y2) then FindColor(x,y,RGB2,x1,y1,x2,y2;
    //end
      end else
        ShowMessage('Could not find icons');
    end.
    juts a couple of tips for you to think about keep it up
    Last edited by Mark; 11-20-2017 at 10:32 PM.
    Previously Known or not Known as CRU1Z1N.
    If you want to succeed you should strike out on new paths, rather than travel the worn paths of accepted success.(John D. Rockefeller)

  7. #7
    Join Date
    Nov 2017
    Posts
    5
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    if you want an "if" statement to do more than one thing you need to include "begin" code "end;" otherwise it will only excute the first line after the "then", in this case "Movemouse(x,y);"

    FindColor(x, y,211426,60,72,1128,690);
    if x>150 then
    Movemouse(x, y);
    sleep(2000);

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
  •