PDA

View Full Version : Using the command goto in a script.



R0b0t1
08-10-2007, 08:30 AM
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:


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
08-10-2007, 05:38 PM
lol i knew about this from batch files but i like your script.

bullzeye95
08-10-2007, 05:42 PM
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
08-16-2007, 05:06 PM
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
08-16-2007, 05:54 PM
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
08-16-2007, 07:08 PM
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.


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
08-16-2007, 08:52 PM
I did. I was verifying. You don't need to be a jerk. I asked a question.

EDIT:Bullzeye = pwnage

bullzeye95
08-16-2007, 09:22 PM
Oh sorry, I was talking to special ed :p

I didn't see your post.

rotflmfwao
08-16-2007, 09:52 PM
Oh nvm then, sry!

Special Ed
08-17-2007, 04:49 AM
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
08-17-2007, 05:00 AM
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
08-19-2007, 01:06 PM
Hmm, I made a tutorial about this ages ago... http://www.villavu.com/forum/showthread.php?t=3890?t=4659