Skip to content

Add sleep duration in world fetching loop#171

Open
XxXAdvisaryXxX wants to merge 1 commit intoWaspScripts:mainfrom
XxXAdvisaryXxX:patch-13
Open

Add sleep duration in world fetching loop#171
XxXAdvisaryXxX wants to merge 1 commit intoWaspScripts:mainfrom
XxXAdvisaryXxX:patch-13

Conversation

@XxXAdvisaryXxX
Copy link
Copy Markdown
Contributor

Super Small Sleep to allow Word.Bounds to be cached while scrollbar is not moving. Before it was just too fast and would mis-cache World.Bounds and would click and hop to wrong world.

When it did that, Self.WaitSwitch(next) then Exit wasn't working because self.World <> next.

The small sleep made it cache the right position and hop to the correct next world.

Super Small Sleep to allow ``Word.Bounds`` to be cached while scrollbar is not moving. Before it was just too fast and would mis-cache ``World.Bounds`` and would click and hop to wrong world.

When it did that, ``Self.WaitSwitch(next) then Exit`` wasn't working because ``self.World <> next``.

The small sleep made it cache the right position and hop to the correct ``next`` world.
@XxXAdvisaryXxX
Copy link
Copy Markdown
Contributor Author

Here's The Snippet I used to figure it out. The fix is commented out and there are writelns to see what's happening.

{$I Wasplib/osrs.simba}   
function TRSWorldSwitcher._Hop(next: Integer): Boolean; Override;
var
  timeout: TCountDown;
  available: TRSWorldArray;
  world: TRSWorld;
begin
  if not Self.IsSorted() and not Self.Sort() then
    Exit;

  timeout.Start(20 * ONE_SECOND);

  repeat
    //Sleep(20,40);
    available := Self.GetWorlds();
    if available = [] then Exit;
    for world in available do
      if world.Number = next then
      begin
        WriteLn 'Entered Next Loop';
        WriteLn ('Current World :' , self.World);
        Mouse.Click(world.Bounds, EMouseButton.LEFT);
        WriteLn next;
        if Self.WaitSwitch(next) then
          Exit(True);
      end;
    Self.Scroll.Scroll(Biometrics.RandomModeInteger(2,1,3), next > available[0].Number);
  until not InRange(Self.Scroll.GetLevel(), 1, 99) or timeout.IsFinished;
end;

function TRSWorldSwitcher.WaitSwitch(world: Integer; failCooldown: Boolean = True): Boolean; override;
begin
  if not SleepUntil(MainScreen.IsServerMessage('Please wait'), 200, 3*TICK) then
  begin
    if failCooldown then
      Self.Cooldown.Restart(0, 7000);
    Exit;
  end;
  Result := SleepUntil(Self.World = world, 200, 10000);
  WriteLn ('World after Hop: ' , Self.World);
end;

begin
   WorldSwitcher.Random();
end;  ```                                                 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant