Results 1 to 17 of 17

Thread: Advanced failsafe tutorial(for noobs and leet scripters alike)

  1. #1
    Join Date
    Sep 2007
    Location
    newcastle australia
    Posts
    240
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Advanced failsafe tutorial(for noobs and leet scripters alike)

    hey guys, i think i better start giving back alot more to the community to earn the auto-memberizing i got, so i decided to make this tutorial on advanced failsafing.

    firstly: this is quite an easy skill to master, its pretty basic coding, and only requires you to think logically, anyone with more then 2 months scar experience will be able to make one of these in under 20 minutes.

    ok, onto the tutorial.
    ill start off with a basic example of a failsafe:

    SCAR Code:
    procedure failsafing;
    var counter:integer;
    begin
      repeat
      wait(500);
      counter:=counter+1;
      until(getcolor(523,235)=244) or (counter=20);
    end;
    ok, so, breaking this down.
    SCAR Code:
    procedure failsafing;  //procedure name, everyone knows this
    var counter:integer;  //declaring the variables, the counter variable should always be a private variable, i.e. inside the script
    begin  //beginning the procedure
      repeat  //start of a repeat.  note: you only need to use failsafes on repeat/while/for commands
      wait(500); //a wait time, this is mainly so it doesnt lag out
      counter:=counter+1;  //this is to count the number of times it waits
      until(getcolor(523,235)=244) or (counter=20); //the failsafe. every time the loop is executed, it'll check if there is color 244(red) at location 523,235. if there is not, it will repeat the loop until the loop is repeated 20 times, as seen by the (counter = 20) command
    end; //basic procedure end command

    ok, so, we are all up to date on basic failsafes.

    after the basics, before the advanced:

    the problem with the failsafe above, is that in the event that the counter hits 20, the script will go on to the next part even though it really hasnt completed this part.
    if this happens, the script will most likely screw up, as it will try to, say, mine a rock while its sitting in a bank.

    so!
    we put an if(fail safe is reached)then terminatescript;
    which is as easy as it looks just there.
    SCAR Code:
    procedure failsafing;
    var counter:integer;
    begin
      repeat
        wait(500);
        counter:=counter+1;
      until(getcolor(523,235)=244) or (counter=20);
      if(counter=20)then
      terminatescript;
    end;
    terminatescript is an SRL command that does exactly what it says.
    alternativly if you are making a multilogin script, you could use this:
    SCAR Code:
    procedure failsafing;
    var counter:integer;
    begin
      repeat
        wait(500);
        counter:=counter+1;
      until(getcolor(523,235)=244) or (counter=20);
      if(counter=20)then
      players[current].active:=false;
      nextplayer;
    end;
    note: im quite rusty with arrays so im pretty sure i did that wrong, if i did, just post here the correct code and ill fix it up.

    what this does is:
    if the character failed the failsafe(i.e. did not find color 244 at 523,235) then it will disable that character, then log out and run the script on the next character like normal.
    every time its the "failed" characters turn to auto, it will automatically skip to the next one

    __________________________________________________ ___________

    ADVANCED FAILSAFES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!

    __________________________________________________ ___________

    EDIT: i just realised that i made a mistake in my talkguy procedure... ill fix it in a second

    ok, enough with the basics.

    the idea behind advanced failsafes is that even if the procedure fails, the script will still be able to function without terminating that particular character.
    ill give you the example i am working on in my tutorial island runner.

    SCAR Code:
    procedure findguy(tehtext1,tehtext2,tehtext3:string);
    var clll,countr: integer;
      heheheheh: boolean;
    begin
      writeln('beggining findguy');
      repeat
      wait(50);
      countr:=countr+1;
      until(myFindObjectdeformed(lulx,luly,tehtext1,tehtext2,tehtext3,lulbmp,msx1,msy1,msx2,msy2)) or (countr=100);
      if(countr=100)then
      begin
      miniwalk;
      findguy(tehtext1,tehtext2,tehtext3);
      end else
      mouse(lulx,luly,1,1,true);
      writeln('found the guy');
      repeat
        wait(300);
        clll := clll + 1;
        if (findnpcchattext('tinue')) or (findnpcchattext('cook')) then heheheheh := true;
      until (heheheheh = true) or (clll = 10);
      if (heheheheh = false)
        then
      begin
        wait(500);
        findguy(tehtext1,tehtext2,tehtext3);
      end;
      cha1:=tehtext1;
      cha2:=tehtext2;
      cha3:=tehtext3;
    end;
    SCAR Code:
    procedure talkguy;
    var countr:integer;
    begin
      repeat;
        if (clicktocontinue)
          then
        begin
          clicktocontinue;
          wait(50);
          mmouse(300, 300, 120, 120);
          repeat
            wait(100);
            countr:=countr+1;
          until (not(findnpcchattext('ait'))) or (countr=15);
        end else
        begin
         wait(100);
         findguy(cha1,cha2,cha3);
         talkguy;
         exit;
      end;
    end; //note: this is not the real end of the script, this end; is only here because the rest of the procedure takes up about 100 lines and really doesnt do anything of interest to you guys
    put simply:
    SCAR Code:
    procedure findguy(tehtext1,tehtext2,tehtext3:string);
    var clll,countr: integer;
      heheheheh: boolean;
    basic stuff here
    [/scar]

    SCAR Code:
    begin
      writeln('beggining findguy');
    this is a little trick if your script hangs, to find out exactly where it gets up to
    SCAR Code:
    repeat
      wait(50);
      countr:=countr+1;
      until(myFindObjectdeformed(lulx,luly,tehtext1,tehtext2,tehtext3,lulbmp,msx1,msy1,msx2,msy2)) or (countr=100);
    basic failsafe.
    SCAR Code:
    if(countr=100)then
      begin
      miniwalk;
      findguy(tehtext1,tehtext2,tehtext3);
    HERE is the Advanced failsafing.
    as you can see, if the failsafe(countr=100) is tripped, then the script will automatically find the place on the minimap where the thing that it wants should be, gets closer to him, and attempts to find him again.
    usually this failsafe requires a failsafe of its own, as it to can start an endless loop, unless you have made the procedures good enough to be pretty much 99% accurate
    SCAR Code:
    end else
      mouse(lulx,luly,1,1,true);
      writeln('found the guy');
      repeat
        wait(300);
        clll := clll + 1;
        if (findnpcchattext('tinue')) or (findnpcchattext('cook')) then heheheheh := true;
      until (heheheheh = true) or (clll = 10);
      if (heheheheh = false)
        then
      begin
        wait(500);
        findguy(tehtext1,tehtext2,tehtext3);
      end;
      cha1:=tehtext1;
      cha2:=tehtext2;
      cha3:=tehtext3;
    end;
    the rest of the stuff you dont really need to worry about. there is another advanced failsafe in there somewhere in case the script clicks on the guy but the guy moves and the script detects that he isnt talking to him.

  2. #2
    Join Date
    Apr 2007
    Location
    Australia
    Posts
    4,163
    Mentioned
    9 Post(s)
    Quoted
    19 Post(s)

    Default

    Pretty nice tutorial, I was thinking of doing something like this

    For this part:

    SCAR Code:
    players[current].active:=false;
      nextplayer;

    you did get the arrays messed up, its meant to be Players[CurrentPlayer] instead. But you could just do NextPlayer(False), which would automatically set the players status to false.

    another way to do failsafes is TimeFromMarks. essentially, they are the same thing as counters, just instead of executions it depends (obviously) on time. you can use them like this:

    SCAR Code:
    MarkTime(YourTime);
    repeat
      Stuff
      if MoreStuff then zzzz := True;
    until zzzz or TimeFromMark(YourTime) > 60000;

    YourTime is an integer. So it repeats everything until it acheives what it wants, or until a minute of trying is up

  3. #3
    Join Date
    Oct 2006
    Location
    Ireland
    Posts
    855
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice tutorial but your standards are awfull >.<

  4. #4
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

    Default

    Ye good TUT use capital letters for some letters, looks neater.

  5. #5
    Join Date
    Sep 2007
    Location
    newcastle australia
    Posts
    240
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    yes, i realise i have terrible CamelCaps, its a problem i will have to remedy.

    TheClaw: ive always shied away from real time orientated scripting. it makes the script alot more unstable if say, the server is lagging badly.

    heres a challenge(albiet quite a simple one)
    this one is a purely logical challenge, see if you can see whats wrong with this part of the script:
    SCAR Code:
    if(countr=100)then
      begin
      miniwalk;
      findguy(tehtext1,tehtext2,tehtext3);
    although it will run, something will happen that will screw up the script if 1 line is not put in.

    hint: the line that needs to be put in is 5 chars long(thats including the semicolon)

  6. #6
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    You forgot:

    SCAR Code:
    Flag;

    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  7. #7
    Join Date
    Sep 2007
    Location
    newcastle australia
    Posts
    240
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    miniwalk has flag built in
    findguy has repeat until(findnpcchattext('lick here'));

    any other takers?

  8. #8
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by elementalelf View Post
    terminatescript is an SRL command that does exactly what it says.
    TerminateScript is a in-built SCAR command. And yea your standards are horrible. Other than that good tut .

    [OFFTOPIC] Santy, what did you do to your avatar?... [/OFFTOPIC]

  9. #9
    Join Date
    Sep 2007
    Location
    newcastle australia
    Posts
    240
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    zephyr: you are right, it is an inbuilt scar command... my bad.

    for all those out there... the missing line was exit;

  10. #10
    Join Date
    Jul 2007
    Location
    America
    Posts
    421
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah, work on standards, but otherwise it's a good tut for people who don't know what failsafing is. Maybe at beginning give a little definition of what failsafes are and why to use 'em?

    And you might want to add something about for to do loops, using break and exit, but that's just a suggestion.

    Good tutorial.
    I dunno, those asians are pretty difficult to out-auto, legend has it they don't need sleep or food...~tim0suprem0
    Activity is on the decline - school's got me
    Check out my tutorial[s] on Color Finding!||Procedures and Functions!

  11. #11
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by elementalelf View Post
    zephyr: you are right, it is an inbuilt scar command... my bad.

    for all those out there... the missing line was exit;
    You can't really tell what you need to put when you only have 3 lines there.
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  12. #12
    Join Date
    Sep 2007
    Location
    newcastle australia
    Posts
    240
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i have the entire procedure as a whole above it

  13. #13
    Join Date
    Jul 2007
    Location
    New Zealand FTW!
    Posts
    72
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks a million

  14. #14
    Join Date
    Aug 2008
    Location
    Auckland
    Posts
    132
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Im having trouble with one certain part of a procedure, with else, its saying i need an identifiyer wtf?
    SCAR Code:
    procedure MineCopper;
    var
      Copper: Boolean;
      Tin: Boolean;
    begin
      if(not(LoggedIn)) then
        Exit;
      repeat
        if(FindColorSpiralTolerance(x, y, CopperColour, MSX1, MSY1,MSX2, MSY2, 3)) or
        (FindColorSpiralTolerance(x, y, CopperColour1, MSX1, MSY1,MSX2, MSY2, 3)) then
          Copper:= True;
        if(Copper = False) then
          TerminateScript;
        else
        begin
          MMouse(x, y, 5, 5);
          if(IsUpText('ine')) then
          begin
            Wait(3000);
            Mouse(x, y, 2, 2, True);
            Wait(3000);
            Writeln('Found Copper');
            Randoms;
          end;
        end;
      until(invfull);
    end;
    Any help would be greatly appreciated
    ~Tom~

  15. #15
    Join Date
    Jul 2007
    Location
    's-Gravenpolder, Holland
    Posts
    204
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This should fix it:

    SCAR Code:
    if(Copper = False) then
          begin
          TerminateScript;
          end
        else

    After then's, always use begin and end (learned this myself yesterday )

  16. #16
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by sirpali View Post
    This should fix it:

    SCAR Code:
    if(Copper = False) then
          begin
          TerminateScript;
          end
        else

    After then's, always use begin and end (learned this myself yesterday )
    No not necessarily. The cause of the identifier expected error is the semicolon before the else statement.

    SCAR Code:
    if(Copper = False) then
          TerminateScript //There can't be a semicolon here
        else

    Using the begin and end just bypasses the problem.

  17. #17
    Join Date
    Jul 2007
    Location
    's-Gravenpolder, Holland
    Posts
    204
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Really? AH! SO that's maybe what's wrong with my script then Thanks

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Trigonometry 101 - Tutorial on Basic Trig Concepts to Help the Advanced Scripter
    By ZephyrsFury in forum OSR Advanced Scripting Tutorials
    Replies: 19
    Last Post: 06-28-2012, 06:38 PM
  2. [Tutorial] Advanced text spammer
    By darklighte in forum C#/Visual Basic Help and Tutorials
    Replies: 10
    Last Post: 11-23-2008, 07:01 AM
  3. The Failsafe Tutorial
    By Cazax in forum OSR Intermediate Scripting Tutorials
    Replies: 8
    Last Post: 05-17-2008, 03:08 AM
  4. Types + PlayerArray Tutorial
    By WhiteShadow in forum Outdated Tutorials
    Replies: 6
    Last Post: 03-05-2007, 05:53 PM
  5. Replies: 4
    Last Post: 01-19-2007, 01:34 AM

Posting Permissions

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