SRL Archive - OSR Advanced Scripting Tutorials

Using the command goto in a script.


R0b0t1

2007-08-10 04:30:19

I put this in the expert section because… Experts would be the only people who cared?


Well, if you are looking at this message in your browser, then you expect an explanation of what "goto" is, right? Well, in my words, it is just a command that makes it skip over a whole part of a script, and execute the part below it.

And, what the Delphi people say it's:

From: Delphi people
Forces a jump to a label, regardless of nesting


W7F r0bot1z0r! What does that mean?

If you had a "It" procedure/thing that had tons of loops in it, you could use goto instead of tons of Break/Exits. So then, how does it work?

First you must declare a label like so:


program TestGoto;

label
TeHLaBeLzOr;

Then, you need to have something to break out of or skip:


program TestGoto;
{.Include SRL/SRL.scar}

Var YouAreGay: Boolean;
Var YouAreTehGay: String;

label
TeHLaBeLzOr;

begin
YouAreTehGay:= ReadLn('Are you gay?');
YouAreGay:= StrToBool(YouAreTehGay);
WriteLn('Testing GoTo command');
Wait(1000);
If not (YouAreGay) Then
goto TeHLaBeLzOr;
WriteLn('If you are straight (like you should be) you will not see this message');
TeHLaBeLzOr:
If not (YouAreGay) Then
WriteLn('Grats! You are NOT gay!');
If (YouAreGay) Then
WriteLn('EWWWWW! SICKO!');
end.

Well, there are more creative uses, like… Doing those errors to mess up leechers?

Well, just be warned that it will still execute the code below the label, unless you make it so it cant somehow.





~r0b0t1 who works in the Department Of Useless Information (DOUI)

jhildy

2007-08-10 13:38:53

lol i knew about this from batch files but i like your script.

bullzeye95

2007-08-10 13:42:59

You should also add that you can't use it to go in, leave, or go to another part of, a loop.

Examples that will not work:

program New;

label
HI;

begin
repeat
HI:
Goto HI;
until(true)
end.
program New;

label
HI;

begin
HI:
repeat
Goto HI;
until(true)
end.
program New;

label
HI;

begin
repeat
Goto HI;
until(true)
HI:
end.

rotflmfwao

2007-08-16 13:06:50

So this is used to skip over stuff in a loop (or wherever) but it cannot step into or break out of loops?

Special Ed

2007-08-16 13:54:27

Also for Goto statement you cannot jump out of or into any loops, include repeats, while, and for to do statements. But what you can do is something like this

program New;
var
x, y, LoopCount, Tol : Integer;
Loop : Boolean;
label Start;
begin
Start:
Loop := False;
Writeln('Start of Loop...');
while(FindColorTolerance(x, y, 123456, 0, 0, 500, 500, Tol))do
begin
Writeln('Looping...');
Wait(500 + Random(50));
LoopCount := LoopCount + 1;
if(LoopCount >= 5)then
begin
Loop := True;
Tol := Tol + 2;
LoopCount := 0;
Break;
end;
end;
if(Loop)then Goto Start;
end.

bullzeye95

2007-08-16 15:08:08

From: bullzeye95
You should also add that you can't use it to go in, leave, or go to another part of, a loop.

Examples that will not work:

program New;

label
HI;

begin
repeat
HI:
Goto HI;
until(true)
end.
program New;

label
HI;

begin
HI:
repeat
Goto HI;
until(true)
end.
program New;

label
HI;

begin
repeat
Goto HI;
until(true)
HI:
end.


From: Special Ed
Also for Goto statement you cannot jump out of or into any loops, include repeats, while, and for to do statements. But what you can do is something like this

program New;
var
x, y, LoopCount, Tol : Integer;
Loop : Boolean;
label Start;
begin
Start:
Loop := False;
Writeln('Start of Loop...');
while(FindColorTolerance(x, y, 123456, 0, 0, 500, 500, Tol))do
begin
Writeln('Looping...');
Wait(500 + Random(50));
LoopCount := LoopCount + 1;
if(LoopCount >= 5)then
begin
Loop := True;
Tol := Tol + 2;
LoopCount := 0;
Break;
end;
end;
if(Loop)then Goto Start;
end.


…

READ PL0X, NUB

rotflmfwao

2007-08-16 16:52:49

I did. I was verifying. You don't need to be a jerk. I asked a question.

EDIT:Bullzeye = pwnage

bullzeye95

2007-08-16 17:22:23

Oh sorry, I was talking to special ed :p

I didn't see your post.

rotflmfwao

2007-08-16 17:52:06

Oh nvm then, sry!

Special Ed

2007-08-17 00:49:57

Lol why, your post doesn't say how you can use it just says how you can't use it… :D just trying to help people out with examples on how to use it. Didn't mean to undermine you just wanted to post the other half of your example.

bullzeye95

2007-08-17 01:00:21

Yeh sorry, firefox was messing up and I didn't realize it. It was randomly not loading all posts. It looked to me like you posted the same thing I did, right after me ;)

MAH BAD

Freddy1990

2007-08-19 09:06:01

Hmm, I made a tutorial about this ages ago… http://www.villavu.com/forum/showthread.php?t=3890?t=4659