Results 1 to 10 of 10

Thread: Fail safe?

  1. #1
    Join Date
    Mar 2009
    Location
    About six feet off the ground.
    Posts
    95
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Fail safe?

    I guess I kind of know what a failsafe is, but I'm not sure how to put it into a script. For example, if I want to make it so that if there isn't a color, to end the script, I would put:
    SCAR Code:
    program Red;
    {.include SRL/SRL.scar}

    var
      x, y: Integer;

    procedure FindRed;
    begin
      if FindColor(x, y, 255, 0, 0, 1027, 775) then
        WriteLn('Red found at ('+IntToStr(x)+', '+IntToStr(y)+').');
        MMouse(x, y);
        ClickMouse(x, y);
    end;

    begin
      ClearDebug;
      SetupSRL;
      FindRed;
    end.
    ...But how do I add a failsafe option of ending the script if SCAR doesn't find color 255? Also, if I could add an option to
    SCAR Code:
    WriteLn('Red not found. Terminating.');
    then could I?
    ~Zeek
    Last major script: November 2009
    Attempted to rejoin: January 2011
    Rejoining: [][][][][]
    Current task: writing basic alching script

  2. #2
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    scar Code:
    program Red;
    {.include SRL/SRL.scar}

    var
      x, y: Integer;

    function FindRed: Boolean;
    begin
      if FindColor(x, y, 255, 0, 0, 1027, 775) then
      begin
        WriteLn('Red found at ('+IntToStr(x)+', '+IntToStr(y)+').');
        MMouse(x, y);
        ClickMouse(x, y);
        Result := True;
      end;
    end;

    begin
      ClearDebug;
      SetupSRL;
      If Not FindRed Then
        Writeln('not found');
    end.
    Last edited by Cazax; 02-18-2011 at 03:45 PM.


  3. #3
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Instead of just using Writeln to report it in the debug, why not make a backup
    .

  4. #4
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Also, you might want to use Mouse instead of ClickMouse... o.O
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  5. #5
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    You could also use the If, else statement without having to made the whole thing a function:

    SCAR Code:
    program Red;
    {.include SRL/SRL.scar}

    var
      x, y: Integer;

    procedure FindRed;
    begin
      if FindColor(x, y, 255, 0, 0, 1027, 775) then
      Begin
        WriteLn('Red found at ('+IntToStr(x)+', '+IntToStr(y)+').');
        MMouse(x, y);
        ClickMouse(x, y);
      end else
      Begin
        WriteLn('Red not found. Terminating.');
        TerminateScript;
      end;
    end;

    begin
      ClearDebug;
      SetupSRL;
      FindRed;
    end.


    Thats actually the if, end else statement, same idea, just for more than 1 line of excutable code after the if and the end else.

  6. #6
    Join Date
    Mar 2009
    Location
    About six feet off the ground.
    Posts
    95
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ha. Never thought I'd get this much feedback.
    Thanks to everyone who replied.
    Here's what I've compiled:
    SCAR Code:
    program Red;
    {.include SRL/SRL.scar}
    var
     x, y: Integer;
    procedure FindRed;
    begin
      if FindColor(x, y, 6124775, 0, 0, 733, 642) then
      Begin
        WriteLn('Color found at ('+IntToStr(x)+', '+IntToStr(y)+').');
        MoveMouse(x, y);
      end else
      Begin
        WriteLn('Color not found.');
      end;
    end;
    procedure Terminate;
    begin
      while not IsKeyDown(chr(13)) do
        Wait(1);
        IsKeyDown(chr(13));
    end;
    begin
      SetupSRL;
      ClearDebug;
      FindRed;
      WriteLn(' ');
      WriteLn('----------------------------');
      WriteLn('------Script finished.------');
      WriteLn('----------------------------');
      WriteLn('-----Press Enter to end-----');
      WriteLn('----------------------------');
      WriteLn(' ');
      Terminate;
    end.
    I modified it a little bit and it works wonders. I also changed the hexdecimal color code to make sure the end else procedure works. And it does.
    Thanks again.
    ~Zeek
    Last major script: November 2009
    Attempted to rejoin: January 2011
    Rejoining: [][][][][]
    Current task: writing basic alching script

  7. #7
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    also just to throw this in.. since i didnt see anyone else say it you can also go:
    SCAR Code:
    if not FindColor(x, y, 6124775, 0, 0, 733, 642) then
    which is pretty much if the color isnt found then do this:
    Lance. Da. Pants.

  8. #8
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    Quote Originally Posted by lancerawks View Post
    also just to throw this in.. since i didnt see anyone else say it you can also go:
    SCAR Code:
    if not FindColor(x, y, 6124775, 0, 0, 733, 642) then
    which is pretty much if the color isnt found then do this:
    Thats basically the longer way of the if, else statement. Does the same thing, but the if,else statement is quicker because it doesn't search for the colour twice.

  9. #9
    Join Date
    Mar 2009
    Location
    England
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Lush

  10. #10
    Join Date
    Mar 2009
    Location
    About six feet off the ground.
    Posts
    95
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    K. I've pretty much used this in all of my scripts, and credit will go to all that helped.
    Thanks, all.
    ~Zeek
    Last major script: November 2009
    Attempted to rejoin: January 2011
    Rejoining: [][][][][]
    Current task: writing basic alching script

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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