• Log in or sign up for an account here: https://www.sythe.org/login

The Failsafe Tutorial

cazax

Forum Addict
Joined
Nov 13, 2007
Sythe Gold
0
Messages
457
This has been posted on srl forums by me too.

Failsafes :)

Failsafes are needed in a script. They save your script from a problem. JageX rotate symbols change colors, etc. The first thing you have to know is:
Else, End Else, And Else// you can you use all of them
or:
if (not(find.....

They are the most used for failsafes.

How To Use Them

Else:
procedure FindSomething;
var
x,y : Integer;
begin
If (FindColor(x,y,152463,MIX1,MIY1,MIX2,MIY2)) then
begin
Writeln(' W00t color was found');
Else
begin
Writeln('Color wasnt found :(');
end;
end;
end;

End Else:
procedure FindSomething;
var
x,y : Integer;
begin
If (FindColor(x,y,152463,MIX1,MIY1,MIX2,MIY2)) then
begin
Writeln(' W00t color was found');
End Else
begin
Writeln('Color wasnt found :(');
end;
// see what happened? end else works as end too
end;

And Else:
procedure FindSomething;
var
x,y : Integer;
begin
If (FindColor(x,y,152463,MIX1,MIY1,MIX2,MIY2)) then
begin
Writeln(' W00t color was found');
And Else
begin
Writeln('Color wasnt found :(');
end;
end;
end;// the same as else

Not:
Procedure FindTree;
var
x,y : Integer;
begin
if (FindColor(x,y,47962,0,0,500,500)) then
begin
Writeln('Tree was found');
if (not(FindColor(x,y,47962,0,0,500,500)) then
begin
Writeln('Tree wasnt found');
end;
end;
end;

Are you understanding now?

Using Them In Your Script

Here i'll teach you how to use them and some examples of failsafes.
Procedure WalkToTheSpot;
var
I,x,y : Integer;
begin
SymbolAccuracy := 0.8;
if (FindSymbol(x,y,'fish')) then
begin
Mouse(x,y,3,3,true);
Exit;
end else
begin
Writeln('couldnt find Fishing spot. trying with radialwalk');
if (RadialWalk(31984,0,360,50,1,1)) then
begin
Writeln('Walking to the fishing spot');
Exit;
And Else
begin
Writeln(' fishing spot was not found');
Logout;
NextPlayer(False);
Exit;
end;
end;
end;
end;

Some Other Examples:

Using an Integer as a Failsafe:
For example you want to find a tree for a certain times. Use this:
Procedure FindAndClickTree;
var
x,y,C : Integer;
begin
repeat
if (FindColor(x,y,214231,0,0,500,500)) then
begin
Mouse(x,y,3,3,true);
Writeln('Chopping...');
End Else
begin
Writeln('Tree wasnt found trying again');
C := +1;
If (C = 10 ) then
begin
Writeln('there isnt any tree here');
Logout;
NextPlayer(False);
Exit;
end;
Until (InvFull)
end;
Here i use C as numbers that count the times that the script doesnt finds the color.

Using a Boolean as a Failsafe:
For Example you want to start a procedure but if something hasnt occurred, the script will skip that procedure. Use this:
Program new;
var
Walked : Boolean;

Procedure WalkToTheTree;
begin
if RadialWalk(64198,0,360,50,1,1) then
begin
Writeln('Walking...');
Walked := True; // here !!!!!!!!!!!
Exit;
end else
begin
Writeln(' Fishing spot wasnt found');
Walked := False; // Or this other !!!!!!!!!!
end;
end;

Procedure ChopTree;
begin
if (Walked = False) then Exit; // Here is the failsafe!!!!
bla bla bla.......
....

The Most Used
Procedure Something;
begin
if (Not(LoggedIn)) then
Exit;
blalbalabla..
...
..
Here, if the current player isnt logged in, the script will skip that procedure.
Or if you want Log in a player:
Procedure Something;
begin
if (not(LoggedIn)) then
LoginPlayer;// here!!!
bla...
...
But remember to declare the players!

Remember this:
Adding failsafes = The script will run for more time and better.
 
Runescape Gamblingrunescape gambling
Back
Top