PDA

View Full Version : The Failsafe Tutorial



Cazax
02-18-2008, 08:27 PM
Welcome to my tut.

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, {$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


{$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;// the same as else or and 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( I'll add more later):

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.

Cya in another tut!

Dynamite
02-18-2008, 08:29 PM
wow sweet tut! very useful :D thank you i am making my first script at the moment so this helps a lot :D rep++

cheers

T ~ M

Cazax
02-18-2008, 08:31 PM
wow sweet tut! very useful :D thank you i am making my first script at the moment so this helps a lot :D rep++

cheers

T ~ M

Thanks The Man np!

[S]paz
02-18-2008, 08:34 PM
nice one but try to explain more, as in for the people that have no idea HOW to use
end else
or something like that, explain how it works
otherwise well done :)

~Spaz

Richard
02-18-2008, 08:56 PM
nice one but try to explain more, as in for the people that have no idea HOW to use
end else
or something like that, explain how it works
otherwise well done :)

~Spaz

I agree the tut is very good for help with failsafes.

Rep :D

Cazax
02-18-2008, 09:01 PM
I agree the tut is very good for help with failsafes.

Rep :D

Im adding thx for the feedback !

Cazax
02-18-2008, 09:18 PM
Added more examples!

jmark9911
05-14-2008, 11:59 PM
thank you very much i found this very useful! this is very helpful to new scripters like me rep++

Immaminor
05-17-2008, 03:08 AM
Getting ready to work on my first script. You help alot, thanks for the wonderful tut.