Can you call goto Label within a Case argument?
Can you call goto Label within a Case argument?
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
You can't use goto (to my knowledge). You can call a procedure though;
Simba Code:Procedure say1;
Begin
Writeln('Looks like the number was 1!');
End;
Procedure say2;
Begin
Writeln('Looks like the number was 2!');
End;
Begin
Case random(2) of
1: say1;
2: say2;
End.
I was wrong, you can't (deleted post because I'm butthurt).
But, I'll say this again because it's important; you shouldn't use goto.
ok so ill just change my
Simba Code:Case Blah of
yeah: goto Whatever
nah: goto IDK
to
Simba Code:if blah = yeah then
goto whatever
else if blah = nah then
goto IDK;
Edit: Yeah when i changes it to if thens it compiled
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
Reasons?
@Yago: you can't use them to break out of or into a loop. I'm thinking that applies to case statements as well, but I honestly don't remember right off the top of my head.
Edit:
Would be "better" anyways as if..then is generally faster than using a Case.
Yeah i changed it to if thens and it worked thanx
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF
^ PDF (obvi). Paper by Edsger Dijkstra called "Go-to statement considered harmful."
I personally like goto cause I save lines of code using it. If not then i would have to make a repeat until loop created a new Boolean set it false for so many things and true if blah... Ive don't it before it wasn't pretty though that's all... and it would be worse it i had a loop within a loop cause I cant break out of it.
That's why i go with goto's
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
You can break out of loops with "Break;"
I see no reason to use goto.
Yeah but as I said, If you have loops within loops within loops then its a lot more annoying.
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
:x I don't see why using a goto and messing with the structure of your script is better than managing loops..
Less code![]()
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
Less code doesn't always mean anything is better. It just leads to more mistakes, less organized code, and more confusion.
Sometimes ... So far its working great for me thanks though
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
Yeah sure ... I'm pretty sure NCDS agrees(at least partially0.
Say I have
Simba Code:repeat
repeat
repeat
until(true1)
if (false1) then
break; //but i want to go to the start ...
// i would have to add the if false thing to everything else...
// say i only wanted to break out of one loop or go to the next part of the function
// its more annoying in my opinion
until(true2)
if (false1) or (false2) then
break
until(true3)
if (false1) or (false2) or false3 then
exit
else ... //go to the next thing
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
Set a value and then break, then check for a certain value and break if it's true/whatever you do.
Point is, there is never a valid reason to use goto over anything else.
Or anything else over goto, but can you show me an example of what you are talking about?
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
Dude, you can almost always avoid using labels someway or another.
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl
"A programmer is just a tool which converts caffeine into code"
Can you show me a code example of where you use goto?![]()
I use it in 2 other places but heres one
Simba Code:Label Starting;
var
A, B, Tries: Integer;
RawInv: TInvItem;
begin
if not (LoggedIn) then
Exit;
begin
Tries := 0;
WriteLn('Running Procedure CookFood.');
Starting:
AntiRandoms;
if (GetPlaneIndex = 0) then
if R_ItemExists(Players[CurrentPlayer].Integers[5], RawInv)then
begin
if not ItemActivated(RawInv.Slot) then
begin
if R_ClickItem(RawInv.Slot,true,'') then
begin
if WaitUntil(5000, ItemActivated(RawInv.Slot)) then
Writeln('Item Is Activated.')
else
Inc(Tries);
if (Tries >= 5) then
begin
EndScript('Item Not Activated.');
Exit;
end;
Goto Starting;
end
else
Inc(Tries);
if (Tries >= 5) then
begin
EndScript('Trouble Clicking Item.');
Exit;
end;
Goto Starting;
Edit: Im looking for efficiency and ease
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
Can you show the whole thing?
Yeah I'm not done fixing it and stuff though. Ill get up up in a bit.
Edit: Here:
Simba Code:Procedure CookFood;
Label Starting;
var
A, B, Tries: Integer;
RawInv: TInvItem;
begin
if not (LoggedIn) then
Exit;
begin
Tries := 0;
WriteLn('Running Procedure CookFood.');
Starting:
AntiRandoms;
if (GetPlaneIndex = 0) then
if R_ItemExists(Players[CurrentPlayer].Integers[5], RawInv)then
begin
if not ItemActivated(RawInv.Slot) then
begin
if R_ClickItem(RawInv.Slot,true,'') then
begin
if WaitUntil(5000, ItemActivated(RawInv.Slot)) then
Writeln('Item Is Activated.')
else
Inc(Tries);
if (Tries >= 5) then
begin
EndScript('Item Not Activated.');
Exit;
end;
Goto Starting;
end
else
Inc(Tries);
if (Tries >= 5) then
begin
EndScript('Trouble Clicking Item.');
Exit;
end;
Goto Starting;
end
else
Writeln('Item Is Activated.');
if (FindCRange) then
begin
AntiRandoms;
ClickMouse2(True)
WriteLn('Clicked On The Cooking Range.');
R_Flag; //If A Couple Tiles Away From The Range.
if WaitUntil(4000, FindText(A, B, 'Raw', StatChars, MCx1, MCy1, MCx2, MCy2)) then
begin
WriteLn('Found The RawDTM In The Chat Box.');
MouseBox(230,395,290,455,1);
if R_WaitUpText('ook', 5000) then
begin
ClickMouse2(True);
WriteLn('Clicked The Chat In An Attempt To Cook.');
if (IsCooking) then
begin
Writeln('Finished Cooking Food.');
IncEx(Players[CurrentPlayer].Integers[7], 1);
stats_IncVariable('Loads Done', 1);
end
else
Inc(Tries);
if (Tries >= 5) then
begin
EndScript('IsCooking Is False.');
Exit;
end;
Goto Starting
end
else
EndScript('Incorrect Uptext in Main Chat for Raw ' + Players[CurrentPlayer].Strings[1] + '.');
end
else
EndScript('Could not find RawText in Chat Box.');
end
else
EndScript('Unable To Find Cooking Range And Cook Food.')
end
else
EndScript('No Raw ' + Players[CurrentPlayer].Strings[1] + ' Exist In The Inventory.')
else
EndScript('Not On The Correct Floor.');
end;
end;
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
You can use a for loop. for tries := 0 to 5 do. Then just break when failed or whatever.
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl
"A programmer is just a tool which converts caffeine into code"
Great idea... I might try but are the labels bad in the script?
"Logic never changes, just the syntax" - Kyle Undefined?
Remember, The Edit Button Is There For A Reason!!!
There are currently 1 users browsing this thread. (0 members and 1 guests)