SRL Archive - Help and Support

"If"..."except end;"...? Help please...


Pure1993

2008-05-04 07:55:18

Can someone please tell me what the "try" and "except end;" commands do, and how they are used? i stumbled across them in Nielsies outdated Tut Island Runner, but those words were too common fo rthe search engine to accept them, and I didn't find any tutorials by scimming through them, also, it is not mentioned in the manual or the help thing in scar 3.15…
Thanks a lot,
Pure1993

JuKKa

2008-05-04 07:59:52

For example when using a array and "runs out of range" and the script crashes.

BUT by using try to can avoid this.

like this:

Try
//runtime error
Except
//then it will jump here
End;
//and continue.

Pure1993

2008-05-04 08:05:36

okay, thanks, but does it do anything else, too? because i can't see how there is an array in this part which could get a runtime error (first of all because there is no array, lol):

function FindMMArrow(var x, y: integer):Boolean;
var
c, tx, ty: integer;
begin
try
repeat
Wait(50);
c := c +1
until (c > 50) or (FindBitmapToleranceIn(TopMMArrow, tx, ty, MMX1, MMY1, MMX2, MMY2, 10)) or (not LoggedIn);

if c > 50 then
begin
c := 0;
repeat
Wait(50);
c := c +1
until (c > 50) or (FindBitmapToleranceIn(MMArrow, tx, ty, MMX1, MMY1, MMX2, MMY2, 10)) or (not LoggedIn);
if c > 50 then
Exit;
end;

Result := True;
x := tx +4;
y := ty +6;
except end;
end;
Anyon know why? (I guess I should go ask nielsie, because it is his script, but I migt incooperate it into my script if it does something useful other than that, and i only have tim right now, and seeing as he isn't online, I'= just thought I'd post it here…)

JuKKa

2008-05-04 08:09:21

From: Pure1993
okay, thanks, but does it do anything else, too? because i can't see how there is an array in this part which could get a runtime error (first of all because there is no array, lol):

function FindMMArrow(var x, y: integer):Boolean;
var
c, tx, ty: integer;
begin
try
repeat
Wait(50);
c := c +1
until (c > 50) or (FindBitmapToleranceIn(TopMMArrow, tx, ty, MMX1, MMY1, MMX2, MMY2, 10)) or (not LoggedIn);

if c > 50 then
begin
c := 0;
repeat
Wait(50);
c := c +1
until (c > 50) or (FindBitmapToleranceIn(MMArrow, tx, ty, MMX1, MMY1, MMX2, MMY2, 10)) or (not LoggedIn);
if c > 50 then
Exit;
end;

Result := True;
x := tx +4;
y := ty +6;
except end;
end;
Anyon know why? (I guess I should go ask nielsie, because it is his script, but I migt incooperate it into my script if it does something useful other than that, and i only have tim right now, and seeing as he isn't online, I'= just thought I'd post it here…)


If u try to run Findbitmap without a loaded bitmap. You would get a error. But with Try Except end it would save it from crashing. What i think it does here.



EDIT

try running this and u'll understand…
Var
C: Integer;
aInt: Array [0..15] of Integer;

Begin
Try
Repeat
Inc ( C );

aInt[C] := 100;
Status(IntToStr(C));
Wait(100);
Until False
Except
Writeln('aInt is more than 15. Exiting');
Writeln('I saved the script from crashing...');
End;
End.

first that


now this.

Var
C: Integer;
aInt: Array [0..15] of Integer;

Begin
Repeat
Inc ( C );

aInt[C] := 100;
Status(IntToStr(C));
Wait(100);
Until False
End.

Pure1993

2008-05-04 08:21:55

Ah, alright, thanks a lot for your help! :)

JuKKa

2008-05-04 08:36:30

From: Pure1993
Ah, alright, thanks a lot for your help! :)


glad i could help

n3ss3s

2008-05-04 09:06:04

Any chance you could've read my tutorial about it?

Pure1993

2008-05-04 09:16:40

um, if you read my post, you would have seen that i tried to find something on it, but the words "if" and "except" were too short or too common to be used in the search engine, so i wasn't able to find anything there, and there are so many tut sections, that the odds of finding a tut, of which you don't even know the name, are quite small…

n3ss3s

2008-05-04 09:30:05

You can do a "Search this Category", it's on the right side, above the section list, I put "runtime" and "error" as the keywords, results: http://www.srl-forums.com/forum/search.php?searchid=613813 and my tut http://www.villavu.com/forum/showthread.php?t=14549?t=16051&highlight=tutorial+runtime

Though you didn't know they were for runtime errors so… Anyways. Gl and Have fun.