Results 1 to 10 of 10

Thread: Loop executes just once?

  1. #1
    Join Date
    Dec 2011
    Posts
    733
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default Loop executes just once?

    This function, it works for normal banks. for bankchests it seems not to. Why, I have no idea, as its the same function in both scenarios...

    This loop only executes once on bank chests...

    Simba Code:
    DebugStr(3,'Waiting for bank and pin screens...');
      MarkTime(T);
      while (not BankScreen) and (not PinScreen) and (TimeFromMark(T) < RandomRange(5000,10000)) do
      begin
        writeln('bscreen: ' + booltostr(BankScreen));
        writeln('pscreen: ' + booltostr(PinScreen));
        writeln(TimeFromMark(T));
        wait(100+random(50));
      end;

    The open bank chest function , and the one containing that loop, is here:
    Simba Code:
    function PinAndBankTest:Boolean;
    var
      T : LongInt;
    begin
      if not LoggedIn then
        Exit;

      Result := false;

      DebugStr(3,'Waiting for bank and pin screens...');
      MarkTime(T);
      while (not BankScreen) and (not PinScreen) and (TimeFromMark(T) < RandomRange(5000,10000)) do
      begin
        writeln('bscreen: ' + booltostr(BankScreen));
        writeln('pscreen: ' + booltostr(PinScreen));
        writeln(TimeFromMark(T));
        wait(100+random(50));
      end;

      if PinScreen then
      begin
        DebugStr(2,'Entering pin...');
        if Length(Players[CurrentPlayer].Pin) = 0 then
        begin
          DebugStr(2,'You did not set a pin, but we are in the pin screen... ' +
                   'Next player...');

          Logout;
          NextPlayer(False);

          Exit;
        end;
        inpin(Players[CurrentPlayer].Pin);
      end;


      DebugStr(3,'Waiting for bank screen...');
      MarkTime(T);
      while not BankScreen and (TimeFromMark(T) < 5000) do
        wait(50+random(50));

      Result := BankScreen;
      if Result then
      begin
        DebugStr(2,'Bank opened succesfully');
        FixBank;
      end else
        DebugStr(2,'Did not find Bank Screen');
    end;

    function Open_BankChest : Boolean;
    var
      OpenSuccess : Boolean;
      a,b,I : Integer;
      TP : TPoint;
      ChestTPA : TPointArray;
      ChestATPA : T2DPointArray;
    begin
      Result := False;

      //first try the recorded bank spot
      MakeCompass('e');
      SetAngle(SRL_ANGLE_HIGH);

      MMouse(ChestBankPoint.x,ChestBankPoint.y,6,6);
      DebugStr(3,'Testing for BankChest');
      if TestRightClickMenu(['Bank'],ChestBankPoint,4,4,1,true) then
      begin
        DebugStr(3,'Remembered Bank Chest position, opening bank...');
        ChooseOption('Bank');
      end else
        DebugStr(3,'Did not remember bank chest position, searching now...');

      SetColorToleranceSpeed(2)
      SetColorspeed2Modifiers(0.110,0.49);

      FindColorsSpiralTolerance(a,b,ChestTPA,11974595,MSX1,MSY1,MSX2,MSY2,14);

      ChestATPA := TPAtoATPA(ChestTPA,40);

      DebugStr(5,'Looping ' +inttostr(Length(ChestATPA)-1) + ' times in search of bank chest');
      for I := 0 to Length(ChestATPA)-1 do
      begin
        TP := MiddleTPA(ChestATPA[I]);

        if TestRightClickMenu(['Bank'],TP,3,3,1,false) then
        begin

          OpenSuccess := ChooseOption('Bank');
          DebugStr(3,'Found Bank Chest; Banking success: '+BoolToStr(OpenSuccess));

          if OpenSuccess then
          begin
            ChestBankPoint := TP;
            break;
          end;
        end;
      end;

      if OpenSuccess then
        Result := PinAndBankTest;
    end;

    Anyone see anything I'm missing?
    My scripts: LunarPlanker
    ---
    My Utilities: Cross Platform, Open Source, SPS Path Generator

    Join the Unoficial SRL Skype Group by clicking here, or visiting this thread.

  2. #2
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

  3. #3
    Join Date
    Dec 2011
    Posts
    733
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    When I execute that loop, it immediately breaks and continues with script. It doesn't loop until bank or pin screen is found. I tried print the values, but they both are false when it breaks
    My scripts: LunarPlanker
    ---
    My Utilities: Cross Platform, Open Source, SPS Path Generator

    Join the Unoficial SRL Skype Group by clicking here, or visiting this thread.

  4. #4
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    To loop a function you use repeat..until - I haven't seen you use that anywhere

  5. #5
    Join Date
    Dec 2011
    Posts
    733
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    I used a while do loop

    It is one of the loop structures, along with for..to..do and repeat..until

    =]
    My scripts: LunarPlanker
    ---
    My Utilities: Cross Platform, Open Source, SPS Path Generator

    Join the Unoficial SRL Skype Group by clicking here, or visiting this thread.

  6. #6
    Join Date
    Dec 2011
    Posts
    195
    Mentioned
    2 Post(s)
    Quoted
    17 Post(s)

    Default

    Tried what happens when you use if..then and repeat..untill instead of while..do?
    --- NexzAuto ---
    --- Simplicity is the ultimate sophistication. - Leonardo Da Vinci ---

  7. #7
    Join Date
    Jul 2009
    Location
    Australia
    Posts
    667
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Is it possibly because one of your failsafe conditions can rr down to around 5 seconds?
    I really cannot see anything wrong with that, have you tried replacing the while with a repeat and until(-conditions-) and checked if that works?

    ~Caotom

  8. #8
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

    Default

    Simba Code:
    MarkTime(c);
      repeat
        Wait(100);
      until (BankScreen) or (PinScreen) or (TimeFromMark(c) > 5000);
      If ((TimeFromMark(c) > 5000)) Then
        Result := False;
      Result := (BankScreen) or (PinScreen);
      If not Result then Writeln('Problem with banking');

    From what Im trying to understand from that fuction, your basically trying to do that ?

  9. #9
    Join Date
    Dec 2011
    Posts
    733
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    That is essentially the same as a while loo, excluding the fact that it will always execute once. right?

    I would test but im capping at cit >.>
    My scripts: LunarPlanker
    ---
    My Utilities: Cross Platform, Open Source, SPS Path Generator

    Join the Unoficial SRL Skype Group by clicking here, or visiting this thread.

  10. #10
    Join Date
    Dec 2011
    Posts
    195
    Mentioned
    2 Post(s)
    Quoted
    17 Post(s)

    Default

    Quote Originally Posted by m34tcode View Post
    That is essentially the same as a while loo, excluding the fact that it will always execute once. right?

    I would test but im capping at cit >.>
    That's correct but trail-and-error still oftenly solves it ;P
    --- NexzAuto ---
    --- Simplicity is the ultimate sophistication. - Leonardo Da Vinci ---

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
  •