SRL Archive - OSR Help

How to use GoTo


Fizzi

2007-09-27 14:14:54

I notice there is a bolded word GoTo in SCAR and I have heard it mentioned briefly. I really have not seen it used much in scripts at all, so I was wondering. What does it do and how is it used?

JuKKa

2007-09-27 14:41:02

very useful!

From my guild miner…


Function Responder: Boolean;
Var
Responce: Array [0..9] of String;
NewLine: String;
Label
ResponceLabel;
Begin
If(Not Loggedin)Then Exit;
If(Not UseResponder)Then Exit;

If(TimeFromMark(ResponceTime)<1000)Then Exit;
MarkTime(ResponceTime);

If(Not LastChatter(LastChatterString))Then Exit;

If(InString(LastChatterString, Players[CurrentPlayer].Nick))Then Exit;

OldLine:= TheLine;
GetLastChatText(TheLine);
NewLine:= TheLine;

If(OldLine = TheLine)Then Exit;

If(InString(TheLine, 'hi')) Or (InString(TheLine, 'ello')) Or (InString(TheLine, 'yo'))Then
Begin
Responce[0]:= 'Hi';
Responce[1]:= 'Hello';
Responce[2]:= 'ello';
Responce[3]:= 'hi lol';
Responce[4]:= 'Hi there';
Responce[5]:= 'yo';
Responce[6]:= 'hi there!';
Responce[7]:= 'Yo wazzap';
Responce[8]:= 'lol hi';
Responce[9]:= 'Hi there';
Result:= True;
GoTo ResponceLabel;
End;

If(InString(TheLine, 'mining lvl')) Or (InString(TheLine, 'mining lev')) Or (InString(TheLine, 'mining lv'))Then
Begin
Responce[0]:= IntToStr(Players[CurrentPlayer].Level[15]);
Responce[1]:= IntToStr(Players[CurrentPlayer].Level[15]) +', You?';
Responce[2]:= IntToStr(Players[CurrentPlayer].Level[15])+ ' lol';
Responce[3]:= 'Currently ' +IntToStr(Players[CurrentPlayer].Level[15]);
Responce[4]:= 'right now ' +IntToStr(Players[CurrentPlayer].Level[15]);
Responce[5]:= 'soon ' +IntToStr(Players[CurrentPlayer].Level[15]+1);
Responce[6]:= 'very soon ' +IntToStr(Players[CurrentPlayer].Level[15]+1);
Responce[7]:= 'secret';
Responce[8]:= 'ask me later';
Responce[9]:= 'ill tell when i get level';
Result:= True;
GoTo ResponceLabel;
End;

ResponceLabel:
If(Result)Then
Begin
Writeln('Responded: '+Responce[CurrentResponce]+' To: '+ TheLine);
TypeSend(Responce[CurrentResponce]);
CurrentResponce:= CurrentResponce + 1;
RespondedTimes:= RespondedTimes + 1;
TRespond:= TRespond + 1;
If(CurrentResponce = 9)Then
CurrentResponce:= 0;
End;
End;

Fizzi

2007-09-27 14:57:53

Ok so… will the code under

ResponceLabel:

be executed only if you use GoTo ResponceLabel, or will it always be executed?

and can this be used in the middle of a procedure? For example:

repeat
if FindObject(...........) then
begin
if(GasCheck(x,y)) then
begin
FTWait(80);
Goto EOLoop;
end;
HitTheRock(x, y);
EOLoop:
end else FailedToFind := FailedToFind + 1;
until(InvFull);

This is just a really bad example I just wrote… so obviously its a shitty piece of code, but would Goto EOLoop;, make it skip the procedure call: HitTheRock?

JuKKa

2007-09-27 15:17:05

U cant use GOTO in a loop :(


Label
ResponceLabel;

Begin
WriteLn('lol');
GoTo ResponceLabel;
WriteLn('this wont be executed');
ResponceLabel:
WriteLn('this will be executed');
End.

Fizzi

2007-09-27 15:21:14

alright, thank you jukka :).

PwNZoRNooB

2007-09-27 15:54:15

I don't like Goto in any programming language. It makes the code look like spaghetti :/

Markus

2007-09-27 16:04:45

Don't use goto's, they are considered harmful.
http://david.tribble.com/text/goto.html