SRL Archive - Outdated Tutorials

Fail-safes, repeat and loop tutorial


solemn wishes

2006-05-14 08:43:30

Fail-safe, repeat and loop -=[tutorial]=-



hey guys,

Well i noticed that some of you may need some help making your procedures and functions do what you want them to do, not skip certain bits because the information that you have entered does not show up straight away. Ok lets begin….


Know a favrout of mine is repeat now i know you are probly saying " yes, repeat does something over and over again…" but thats not true, like i said before i noticed that a great number of you use bassicly dead-end procedures E.G.

if(findcolorspiraltolerance(x,y,color,x1,y1,x2,y2,tolerance))then

This is completly fine to use if you know that the color works, the bitmap ect ect but what if the color slightly changes? or the bitmap becomes slighty different? this is where i have grown to use repeat as a failsafe for my scripts. A "basic" example of using this type of scritping it is….

Function test:boolean;
var tol : integer;
begin
repeat
if(findcolorspiraltolerance(x,y,color,x1,y1,x2,y2,tol))then
begin
writeln('Color found with a tolerance of:'+Inttostr(tol))
result:= true;
end;
if not result then
tol:= tol+1;
until result or (tol=50)
end;


This small peice of code will play a big part in making sure that all your scripts run through smoothly and not skip peices that may be vital for it to run. Know lets brake down this code and explain each part…..



[PHP]function test:boolean; // simply declairs the name of the function[/PHP]

[PHP]var tol : integer; // these are our vars, all integers start with a value of 0 [/PHP]

[PHP]if(findcolorspiraltolerance(x,y,color,x1,y1,x2,y2,tol))then //searches for the color and if found will begin the next loop[/PHP]
[PHP]writeln('Color found with a tolerance of:'+Inttostr(tol)) // give information of the ammount of tolerance used, this could be mouse movements[/PHP]
result:= true; // decalirs that the result is true, or succesfull

[PHP]if not result then // states that if the result was not true, if the color was not found it will do the follwoing[/PHP]

[PHP] tol:= tol+1; // increases the tolerance depending on the success of the color finding[/PHP]

[PHP]until result or (tol=50) // ends the repeat depending if the color finding was succesfull or if the tolerance has exceeded the ammount stated [/PHP]



Ok so you now should know the basics of how to use repeat as a fail-safe, now we can take this a step further by using commands such as "while" and "do" to make our code shorter, a lil more complex and in some ways better…we could use this….

[PHP]while(tol<50)do //this bassicly says while the var "tol" is bellow 50 do the following[/PHP]

we could change this to…

[PHP]while(tol>50)do //this says while the tolerance is above 50 do, this will not work in our code but you may find use for it later.[/PHP]


well i hope this helps some of you to inprove you scripting ability's and maybe stop some of the errors that could be going on, thx….

c0de

2006-05-14 08:45:23

err.. Nice, I guess :) but correct some mistakes like

scritping
decalirs
peice
completly
probly
bassicly
brake
succesfull
ability's


no hard feelings, learn on your past mistakes :)

solemn wishes

2006-05-14 08:53:38

hehe, i think nearly everyone allmost expects it from know that i will make a million spelling mistakes, however i did spell "tutorial" correctly for once :)

WT-Fakawi

2006-05-14 08:59:26

good thinking Solemn.
I always wanted to make one myself, but hoped that by releasing many scripts people would learn how to make good loops themselves :)

Explain too about timed loops using GetTickCount/GetSystemTime/MarkTime etc.

Dont forget the
if not loggedin then break;


GJ!

solemn wishes

2006-05-14 09:07:16

thx Fakawi, ill start extending the tutorial with what you mentioned know.

o ya and thx for the lil award thingy…:)

ub3r |<1||3r*1337*

2006-05-14 09:43:56

make a video of this… I dont like reading :D

good job though!

Pwnd

2006-05-14 11:38:27

From: c0de
err.. Nice, I guess :) but correct some mistakes like


no hard feelings, learn on your past mistakes :)

You forgot favrout :D

We need more tuts like this.

WhiteShadow

2006-05-14 12:44:33

if(findcolorspiraltolerance(x,y,color(x1,y1,x2,y2,tolerance))then

Lol, maybe edit that.

Sweet. People can really learn from this. :)

solemn wishes

2006-05-14 16:32:44

From: WhiteShadow
if(findcolorspiraltolerance(x,y,color(x1,y1,x2,y2,tolerance))then

Lol, maybe edit that.

Sweet. People can really learn from this. :)



o dam sry about that lol, must of been when i was adding the tags…thx for the comments :)

phantombmx

2006-05-14 20:35:08

looks good! there is also the
for i:=0 to blah do
if(findcolortolerance(x, y, color, MMX1, MMY1, MMX2, MMY2, i))then
begin
writeln('Found color with tolerance of : '+inttostr(i));
result:=true;
break;
end;

The Un-Named

2006-05-14 23:09:41

What I found useful is "until not(condition);". That way if it dosen't find the color then it breaks out of the loop. :)

solemn wishes

2006-05-18 03:23:54

thx for the comments :), im going to post a slightly extended version soon…this will include timings ect ect

Keen

2006-05-18 08:03:31

From: solemn wishes
thx for the comments :), im going to post a slightly extended version soon…this will include timings ect ect


Great tutorial solemn.
Can't wait for the next version. :D

Btw, spell check it before posting it. :p

Cheesehunk

2006-05-20 21:11:05

Thanks for the tutoriol, helped me!

Mariuswbz

2007-11-28 12:13:21

Nice tut solemn.
I really like this and your scripts :)
Keep up good work.

- Marius

Rs-Gp-4U

2007-12-12 04:22:04

you might want to change to
 
?