Results 1 to 7 of 7

Thread: Using labels / goto command for failsafe

  1. #1
    Join Date
    Dec 2012
    Posts
    73
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default Using labels / goto command for failsafe

    Hello,

    my script starts to do what it was made to do, only problem now is failsafes.
    Basically as soon as something went wrong I want a few procedures to teleport back to a lodestone and restart / jump to a specific point in the main loop. I hear a lot that this is bad practice so if anybody has a better idea how to do this I would be very happy to hear about it.

    So I tried to use labels.
    I defined it at the top of the program and set the label in the main loop so the script knows where to jump to:

    Code:
    Program WalkFromStartToDwarven;
    
    {$DEFINE SMART}
    {$i srl/srl.simba}
    {$i sps/sps.simba}
    
    label RepeatEverythingFromBurthorpe;
    
     var
      WalkToGatePath:TPointArray;
      FromLodestoneToMineEntrancePath:TPointArray;
    
    (...)
    
     SRL_SixHourFix := True;
     SetupSRL;
     StartLogin;
     setglobals;
     HideWheelOfFortune;
     RepeatEverythingFromBurthorpe:
     WalkToGate;
     TurnToMakeGateOpenScriptWork;
     OpenGate;
     RadWalkFromGateToLodestone;
     ActivateLodestone;
     FromLodestoneToMineEntrance;
     EnterMine;
    So far, so good, the script compiles. But then I can't use the goto command in a procedure. When using the goto command in the main loop (where it isn't of any use to me period) everything compiles nicely:

    Code:
    begin
     SRL_SixHourFix := True;
     SetupSRL;
     StartLogin;
     setglobals;
     HideWheelOfFortune;
     RepeatEverythingFromBurthorpe:
     WalkToGate;
     TurnToMakeGateOpenScriptWork;
     OpenGate;
     RadWalkFromGateToLodestone;
     ActivateLodestone;
     FromLodestoneToMineEntrance;
     EnterMine;
     goto RepeatEverythingFromBurthorpe
    
    end.
    But when I try to use it in a procedure (ANY procedure, no if... then loops included so no error there) like this:

    Code:
    procedure test;
    
    begin
    goto RepeatEverythingFromBurthorpe
    end;
    I get a compiling error:
    Unknown identifier 'RepeatEverythingFromBurthorpe' at line 173

    Could somebody help me out?
    Here is the whole script, the relevant parts are in bold:

    Code:
    Program WalkFromStartToDwarven;
    
    {$DEFINE SMART}
    {$i srl/srl.simba}
    {$i sps/sps.simba}
    
    label RepeatEverythingFromBurthorpe;
    
     var
      WalkToGatePath:TPointArray;
      FromLodestoneToMineEntrancePath:TPointArray;
    
    
    
    procedure DeclarePlayers;
    begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;
    
      with Players[0] do
      begin
        Name       := ''; // Player username
        Pass       := ''; // Player password
        BoxRewards := ['XP', 'ostume', 'mote', 'oins', 'une', 'ssence'];
        LampSkill  := Skill_Mining;
        Active     := True;
      end;
    end;
    
    
    
    Procedure StartLogin;
    
    begin
      ClearDebug;
      {$IFDEF SMART}
        {$IFDEF SIMBAMAJOR980}
          Smart_Server := 10;
          Smart_Members := False;
          Smart_Signed := True;
          Smart_SuperDetail := False;
        {$ELSE}
          SRL_SixHourFix := True;
          Smart_FixSpeed := True;
        {$ENDIF}
      {$ENDIF}
      DeclarePlayers;
      LoginPlayer;
    
    end;
    
    Procedure WalkToGate;
    
    begin
      SPS_WalkPath(WalkToGatePath);
      Writeln('Walked to the gate. Waiting for 4 seconds.');
      Wait(4000);
      end;
    
    Procedure OpenGate;
    
    var
        x, y: Integer;
    begin
    if FindObjCustom(x, y, ['Open Gate'], [3622483, 3094077], 3)
    then
      begin
      Writeln('Gate found. Clicking.');
      ClickMouse(x, y, mouse_Left);
      Writeln('OK, clicked on the gate. Waiting for 12 seconds for the process to finish...');
      Wait(12000);
      end
    else Writeln('Gate not found, is it already open? Checking...');
      if FindObjCustom(x, y, ['Close Gate'], [3622483, 3094077], 3)
      then begin Writeln('Gate is already open! Continuing with walking.')
           Exit;
           end
      else
      Writeln('Something might have gone wrong, no gate in sight, neither open or closed. Teleporting back to Burthorpe.');
      LodestoneTeleport('Burthorpe');
    end;
    
    
    Procedure HideWheelOfFortune;
    
    begin
    MoveMouse(658,285);
    ClickMouse(658, 285, mouse_Left);
    end;
    
    Procedure TurnToMakeGateOpenScriptWork;
    
    begin
      KeyDown(37);
      wait(1000);
      KeyUp(37);
      wait(3000);
    end;
    
    
    Procedure ActivateLodestone;
    
    var
         x, y: Integer;
    
    begin
      if FindObjCustom(x, y, ['Act', 'Fal'], [7371393], 3) then
      begin
      Mouse(x,y,2,2,true);
      ClickMouse(x, y, mouse_Left);
                 Wait(20000);
                 Exit;
      end
    
      else begin
      Writeln('Oh noes, what happened? No lodestone in sight... Is it already activated?');
                      //LodestoneTeleport('Burthorpe');  //In case you need one, here is a failsafe you can use.
           end;
    
    end;
    
    Procedure FromLodestoneToMineEntrance;
    
    begin
      SPS_WalkPath(FromLodestoneToMineEntrancePath);
      Writeln('Walked to the mine entrance. Waiting for 15 seconds.');
      Wait(15000);
    end;
    
    
    Procedure RadWalkFromGateToLodestone;
    
    begin
    RadialWalkTolerance(4612971,0,90,70,1,1,10);
    RadialWalkTolerance(4612971,40,90,70,1,1,10);
    RadialWalkTolerance(4612971,40,90,70,1,1,10);
    RadialWalkTolerance(9589358,0,360,70,1,1,5);
    end;
    
    Procedure EnterMine;
    
    var
        x, y: Integer;
    begin
    if FindObjCustom(x, y, ['Cli', 'Lad'], [3630462, 2183788], 10)
    then begin Mouse(x,y,2,2,true);
               ClickMouse(x, y, mouse_Left);
               Wait(10000);
               Exit;
         end
    
    else begin Writeln('Now where is that ladder? Firing up failsafe!');
               LodestoneTeleport('Falador');
         end;
    end;
    
    
    
    Procedure setglobals;
    begin
    
    SPS_Setup(RUNESCAPE_SURFACE,['7_5', '7_6', '7_7', '8_5', '8_6', '8_7', '9_6', '9_7']);//SPS Areas
    WalkToGatePath := [Point(3380, 2443), Point(3398, 2473), Point(3429, 2472), Point(3477, 2473), Point(3474, 2517), Point(3470, 2565), Point(3468, 2611), Point(3472, 2616), Point(3478, 2624), Point(3481, 2675), Point(3484, 2721), Point(3488, 2758), Point(3486, 2790), Point(3488, 2840), Point(3544, 2841)];
    FromLodestoneToMineEntrancePath := [Point(3669, 2960), Point(3694, 2942), Point(3730, 2925), Point(3750, 2896), Point(3770, 2872), Point(3797, 2872), Point(3834, 2863), Point(3859, 2810)];
    
    end;
    
    
    procedure test;
    
    begin
    goto RepeatEverythingFromBurthorpe
    end;
    
    
    begin
     SRL_SixHourFix := True;
     SetupSRL;
     StartLogin;
     setglobals;
     HideWheelOfFortune;
     RepeatEverythingFromBurthorpe:
     WalkToGate;
     TurnToMakeGateOpenScriptWork;
     OpenGate;
     RadWalkFromGateToLodestone;
     ActivateLodestone;
     FromLodestoneToMineEntrance;
     EnterMine;
    
    end.

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    You cannot do that. If you were able to do that, you would be able to jump from function to function without the stack cleaning up and unwinding. This behaviour would be ridiculous. In Interpreted languages, this would be even worse lol. try to imagine an interpreter reading from top to bottom. You decide to jump to the top before it's even finished. The tokens and parsing would really get messed up as it reads while it goes along the code; line by line, left to right.

    For this reason, Labels/Goto's are scope/block defined in every language I've came across except ASM. They only exist within the function they're declared within. You cannot have a global label.
    Last edited by Brandon; 12-30-2012 at 06:20 PM.
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    You can put the Burthorpe tasks into one procedure, and if the script fails just call that procedure.

  4. #4
    Join Date
    Jul 2012
    Posts
    279
    Mentioned
    5 Post(s)
    Quoted
    46 Post(s)

    Default

    One option is to add a condition at the beginning of each function/procedure. That way, if you aren't at the right place to call it, it'll simply exit. This way, you end up doing the same as a label, yet not skip any line.

    Example:
    Simba Code:
    if not BankScreen then
      Exit;

    You can be very creative with those.

  5. #5
    Join Date
    Dec 2012
    Posts
    73
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default

    Hey, just rewrote the whole code to use labels as you should, however your suggestion Wardancer looks interesting too. Trouble is I need a failsafe that restarts the script, not merely exits a loop. Is this possible with this method?

  6. #6
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Like this?
    Simba Code:
    begin
      SRL_SixHourFix := True;
      SetupSRL;
      StartLogin;
      setglobals;
      HideWheelOfFortune;
      repeat //I added this
       // RepeatEverythingFromBurthorpe: //Took out this
        WalkToGate;
        TurnToMakeGateOpenScriptWork;
        OpenGate;
        RadWalkFromGateToLodestone;
        ActivateLodestone;
        FromLodestoneToMineEntrance;
        EnterMine;
       // goto RepeatEverythingFromBurthorpe // I took out this
     until(not LoggedIn); // and added this
    end.

    See if that works with Wardancers method

  7. #7
    Join Date
    Dec 2012
    Posts
    73
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default

    Thanks to you two, I managed to get it done with several repeat loops, two of them nested.
    After rewriting the code I only have two procedures left, so I added a boolean variable that gets changed to "true" when something is successful and "false" is there is an error. This way I can trigger the failsafe without using any labels.

    Code:
    if FindObjCustom(x, y, ['Cli', 'Lad'], [3630462, 2183788], 10) then
         begin Writeln('Found ladder, clicking...');
               Mouse(x,y,2,2,true);
               ClickMouse(x, y, mouse_Left);
               EnterMineSuccess:=True;
               Wait(10000);
           end else
               begin Writeln('Now where is that ladder? Firing up failsafe!');
               LodestoneTeleport('Falador');
               EnterMineSuccess:=False;
    	         Wait(20000);
    	         //goto FaladorBegin;
               end;
    until(EnterMineSuccess = True);

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
  •