PDA

View Full Version : Fail-safes, repeat and loop tutorial



solemn wishes
05-14-2006, 12:43 PM
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.....




function test:boolean; // simply declairs the name of the function


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


if(findcolorspiraltolerance(x,y,color,x1,y1,x2,y2, tol))then //searches for the color and if found will begin the next loop

writeln('Color found with a tolerance of:'+Inttostr(tol)) // give information of the ammount of tolerance used, this could be mouse movements
result:= true; // decalirs that the result is true, or succesfull


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


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


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



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....


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

we could change this to...


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.


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
05-14-2006, 12:45 PM
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
05-14-2006, 12:53 PM
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
05-14-2006, 12:59 PM
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
05-14-2006, 01:07 PM
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*
05-14-2006, 01:43 PM
make a video of this... I dont like reading :D

good job though!

Pwnd
05-14-2006, 03:38 PM
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
05-14-2006, 04:44 PM
if(findcolorspiraltolerance(x,y,color(x1,y1,x2,y2, tolerance))then

Lol, maybe edit that.

Sweet. People can really learn from this. :)

solemn wishes
05-14-2006, 08:32 PM
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
05-15-2006, 12:35 AM
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
05-15-2006, 03:09 AM
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
05-18-2006, 07:23 AM
thx for the comments :), im going to post a slightly extended version soon...this will include timings ect ect

Keen
05-18-2006, 12:03 PM
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
05-21-2006, 01:11 AM
Thanks for the tutoriol, helped me!

Mariuswbz
11-28-2007, 05:13 PM
Nice tut solemn.
I really like this and your scripts :)
Keep up good work.

- Marius

Rs-Gp-4U
12-12-2007, 09:22 AM
you might want to change to [ SCAR ] [ /SCAR ]?