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