SRL Archive - OSR Help

Help With GoTo and should i use it?


Troll

2011-12-28 15:39:24

Ok so for my main loop, im thinking of using GoTo for when something returns false

Repeat
Fail:
Text About failing using a var string pre set
break
If Not Walk Then GoTo Fail
If Not Bank Then GoTo Fail
etc etc

Until(False)

or something like that for should i just write breaking out and text under each If Then part?

And the question about i had about GoTo Would it only use the Fail When i use GoTo?

Thanks for the help

Brandon

2011-12-28 16:31:04

From: Troll
Ok so for my main loop, im thinking of using GoTo for when something returns false

or something like that for should i just write breaking out and text under each If Then part?

And the question about i had about GoTo Would it only use the Fail When i use GoTo?

Thanks for the help


From experience in other languages, goto leaves all the previous instructions in memory.. I don't know how pascal/simba handles this.. I've used it in Simba and had no problems before.. Other times I get a problem so I use a case statement instead.

"Would it only use it…"

It will only jump to the fail: label when you call "Goto Fail;"

Here's how ur above code will run:

This prints first..
[LEFT]

Text About failing using a var string pre set
break; //This will break out of your code.. thus the rest never gets executed.



Function bleh: boolean;
var
Fail: Label;
DidFail: Boolean;
begin
Repeat
DidFail:= False;
Fail:
if (DidFail) then
begin
writeln('Text About failing using a var string pre set');
break;
end;

If Not Walk Then GoTo Fail;
If Not Bank Then GoTo Fail;
writeln('We got this far.. All of the above executed nicely..');

Until(False);
end;

///Whereas you can use this instead:

Function meh: Boolean;
var
DidFail: Boolean;

begin
DidFail:= False;

Repeat
if (DidFail) then
begin
writeln('Text About failing using a var string pre set');
break;
end;

If ((Not Walk) or (Not Bank)) Then
begin
DidFail:= True;
continue; //This is where the magic is at.. That nice continue statement.
end;

writeln('We got this far.. All of the above executed nicely..');
Until(false);
end.

[/LEFT]

JuKKa

2011-12-28 16:37:08

You cant use GOTO in loops (for to do, repeat or while)
you will have to assign some kind of variable and break out of the loop to use the goto command later. This is an example from a script of mines banking loop how i break out.


For I:= 0 To 2 Do
Begin
If(ExistsItemDTM(DTMs[I], X, Y))Then
Inc(F)//Found this ITEM (nature rune)
Else
Begin
If(I = 0)Then //
NoRunes := True;
End;
End;

If(NoRunes)Then
Goto HandleRunes;

if you need i can post the whole banking procedure.

Narcle

2011-12-28 16:46:02

off topic but
Holy crap JUKKA!