Page 1 of 2 12 LastLast
Results 1 to 25 of 39

Thread: Labels

  1. #1
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default Labels

    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!!!

  2. #2
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

  3. #3
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    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.

  4. #4
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  5. #5
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by i luffs yeww View Post
    Sure. I wouldn't recommend using goto's though.
    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:
    Quote Originally Posted by Yago View Post
    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
    Would be "better" anyways as if..then is generally faster than using a Case.

  6. #6
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  7. #7
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    Reasons?
    http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF

    ^ PDF (obvi). Paper by Edsger Dijkstra called "Go-to statement considered harmful."

  8. #8
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  9. #9
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    You can break out of loops with "Break;"

    I see no reason to use goto.

  10. #10
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  11. #11
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    :x I don't see why using a goto and messing with the structure of your script is better than managing loops..

  12. #12
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    Less code
    "Logic never changes, just the syntax" - Kyle Undefined?

    Remember, The Edit Button Is There For A Reason!!!

  13. #13
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Less code doesn't always mean anything is better. It just leads to more mistakes, less organized code, and more confusion.

  14. #14
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  15. #15
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by Yago View Post
    Less code
    I've been taught not to use them. It's for your overview and the layout of script, apart from the practical issues.

    Can you give an example of a loop inside a loop inside a loop. I'm sure it can be done different, without extreme nesting nor using goto .

  16. #16
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  17. #17
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    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.

  18. #18
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  19. #19
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    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)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  20. #20
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Can you show me a code example of where you use goto?

  21. #21
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  22. #22
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Can you show the whole thing?

  23. #23
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

  24. #24
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    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)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  25. #25
    Join Date
    Dec 2009
    Location
    R_GetPlayerLoc;
    Posts
    2,235
    Mentioned
    0 Post(s)
    Quoted
    14 Post(s)

    Default

    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!!!

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •