SRL Archive - SRL Archives

NextPlayer(Active) and SwitchToPlayer(PlayerNo, Active): boolean


bugger0001

2009-06-17 21:28:03

I THINK there's a little error while using NextPlayer(Active)
function SwitchToPlayer(PlayerNo: Integer; Active: Boolean): Boolean;
begin
WriteLn('SwitchToPlayer(PlayerNo: ' + IntToStr(PlayerNo) + ', Active: ' + BoolToStr(Active)+ ');');
Players[CurrentPlayer].Active := Active;
Logout;
if (SRL_Procs[srl_OnNextPlayer] <> nil) then
SRL_Procs[srl_OnNextPlayer]();
PlayerCurTime := (GetSystemTime div 1000);
Players[CurrentPlayer].Worked := Players[CurrentPlayer].Worked + ((PlayerCurTime - PlayerStartTime) / 60);
CurrentPlayer := PlayerNo;
SRL_Logs := SRL_Logs + 1;
LoginPlayer;
Result := LoggedIn;
end;

procedure NextPlayer(Active: Boolean);
var
srl_PlayerIndexFunc: function: Integer;
begin
if (RandomPlayer) then
srl_PlayerIndexFunc := @RandomPlayerIndex
else
srl_PlayerIndexFunc := @NextPlayerIndex;

WriteLn('NextPlayer');
LogOut;
CurrentPlayer := srl_PlayerIndexFunc();
while (CurrentPlayer = -1) do
begin
CurrentPlayer := srl_PlayerIndexFunc();
if (SRL_Procs[srl_InNextPlayerLoop] <> nil) then
SRL_Procs[srl_InNextPlayerLoop]();
Wait(5000); //Endless loop
end;

SwitchToPlayer(CurrentPlayer, Active);
end;
Wouldn't calling NextPlayer(False); make it go this:
1. Defines the number of next player
2. Logs out current player
3. Sets CurrentPlayer to the number next player
4. Checks if there's still players active
5. Calls SwitchToPlayer setting PlayerNo to CurrentPlayer and Active to False.

In SwitchToPlayer goes like this:
I: Sets the forecoming players(var CurrentPlayer was already changed in NextPlayer) Active to False
II: Tries to LogOut again
III: Then comes the timing part
IV: CurrentPlayer gets changed to PlayerNo(Which it already is from NextPlayer)
V: Tries to log in the player, but as it's Active is False fails

All above gets repeated until all players are set inactive. Correct me if I'm wrong.

Runescapian321

2009-06-17 21:29:42

OMG! I was wondering why when one player went false in my and Cnr Sport's new Essminer every single one went false… I've spent the last hour searching for why - Didn't think it was SRL :p

I hope you're right lol.

bugger0001

2009-06-17 21:34:43

From: Runescapian
OMG! I was wondering why when one player went false in my and Cnr Sport's new Essminer every single one went false… I've spent the last hour searching for why - Didn't think it was SRL :p

I hope you're right lol.


Well I debugged every single line of all my scripts and thought it was me doing something wrong, but then thought that maybe the ub3rl33t SRL has a bug in it. Found it!

Nava2

2009-06-17 22:01:16

{*******************************************************************************
procedure NextPlayer(Active: Boolean);
By: ZephyrsFury
Description: Logs in the next player that isn't inactive.
Boolean: True - Current player is ok. False - Current player is false.
*******************************************************************************}

procedure NextPlayer(Active: Boolean);
var
srl_PlayerIndexFunc: function: Integer;
cP: Integer;
begin
if (RandomPlayer) then
srl_PlayerIndexFunc := @RandomPlayerIndex
else
srl_PlayerIndexFunc := @NextPlayerIndex;

WriteLn('NextPlayer');
LogOut;
cP := srl_PlayerIndexFunc();
while (cP = -1) do
begin
cP := srl_PlayerIndexFunc();
if (SRL_Procs[srl_InNextPlayerLoop] <> nil) then
SRL_Procs[srl_InNextPlayerLoop]();
Wait(5000); //Endless loop
end;

SwitchToPlayer(cP, Active);
end;

Fix'd.

Sir R. M8gic1an

2009-06-17 22:15:58

c-c-c-c-c-closed!

nice catch ;)

~RM

ZephyrsFury

2009-06-18 07:30:52

Woops… mah bad. :(