kakadudl
06-22-2017, 06:45 PM
Hey guys! So I'm making myself an include for private use and I ran into a problem. I'm sure it's a simple one but yet I can't find it.
The thing is:
I got main script and then my include which includes login.simba and waiting.simba (There's more but these things matter).
Functions from include work in my script so I guess this isn't a problem of the include.
The problem is with this function:
function WaitUntil(event : Boolean; interval, maxWait : Integer) : Boolean; //Higher interval less lag!!!
var
startTime, timer : Integer;
begin
startTime := GetSystemTime;
repeat
Wait(interval);
timer := GetSystemTime;
until(event) or ((timer - startTime ) > maxWait);
Writeln(timer - startTime);
if event then
Result := True;
end;
So as you can see this function is supposed to wait until certain event is true. When I call this function (in login.simba) I do it three times:
WaitUntil(isWarningScreen, 1223, 8000);
WaitUntil(isCredsScreen, 333, 8000);
WaitUntil(isLoggedIn, 666, 25000);
First two work fine, events result in true and it stops waiting when it's supposed to.
But when account logs in (when WaitUntil(isLoggedIn, 666, 25000) is being executed) it won't stop waiting even though isLoggedIn is True if I don't call it in WaitUntil function.
Functions that are used:
function GetLoginState() : Integer;
var
whiteCount, yellowCount : Integer;
begin
if FindColorTolerance(x, y, 209112, 596, 56, 611, 71, 5) then
Exit(LS_LOGGEDIN);
whiteCount := CountColor(WHITE_TEXT, CX1, CY1, CX2, CY2);
if whiteCount > 3200 then
Exit(LS_WORLDSELECT);
yellowCount := CountColor(YELLOW_TEXT, CX1, CY1, CX2, CY2);
if yellowCount > 2000 then
Exit(LS_CLICKPLAY);
Result := LS_LOGGEDOUT;
end;
function isLoggedIn() : Boolean;
begin
Result := GetLoginState() = LS_LOGGEDIN;
end;
function isWorldScreen() : Boolean;
begin
Result := GetLoginState() = LS_WORLDSELECT;
end;
function isPlayScreen() : Boolean;
begin
Result := GetLoginState() = LS_CLICKPLAY;
end;
function GetLoginScreen() : Integer;
var
yellowCount : Integer;
begin
yellowCount := CountColor(YELLOW_TEXT, CX1, CY1, CX2, CY2);
if yellowCount = 479 then
Exit(0); //Welcome screen
if (yellowCount = 210) or (yellowCount = 439) then
Exit(1); //Warning screen
if (yellowCount = 1037) or (yellowCount = 1061) then
Exit(2); //Credentials screen
end;
function isWelcomeScreen() : Boolean;
begin
Result := GetLoginScreen = LS_WELCOME;
end;
function isWarningScreen() : Boolean;
begin
Result := GetLoginScreen = LS_WARNING;
end;
function isCredsScreen() : Boolean;
begin
Result := GetLoginScreen = LS_CREDS;
end;
Any help appreciated!
The thing is:
I got main script and then my include which includes login.simba and waiting.simba (There's more but these things matter).
Functions from include work in my script so I guess this isn't a problem of the include.
The problem is with this function:
function WaitUntil(event : Boolean; interval, maxWait : Integer) : Boolean; //Higher interval less lag!!!
var
startTime, timer : Integer;
begin
startTime := GetSystemTime;
repeat
Wait(interval);
timer := GetSystemTime;
until(event) or ((timer - startTime ) > maxWait);
Writeln(timer - startTime);
if event then
Result := True;
end;
So as you can see this function is supposed to wait until certain event is true. When I call this function (in login.simba) I do it three times:
WaitUntil(isWarningScreen, 1223, 8000);
WaitUntil(isCredsScreen, 333, 8000);
WaitUntil(isLoggedIn, 666, 25000);
First two work fine, events result in true and it stops waiting when it's supposed to.
But when account logs in (when WaitUntil(isLoggedIn, 666, 25000) is being executed) it won't stop waiting even though isLoggedIn is True if I don't call it in WaitUntil function.
Functions that are used:
function GetLoginState() : Integer;
var
whiteCount, yellowCount : Integer;
begin
if FindColorTolerance(x, y, 209112, 596, 56, 611, 71, 5) then
Exit(LS_LOGGEDIN);
whiteCount := CountColor(WHITE_TEXT, CX1, CY1, CX2, CY2);
if whiteCount > 3200 then
Exit(LS_WORLDSELECT);
yellowCount := CountColor(YELLOW_TEXT, CX1, CY1, CX2, CY2);
if yellowCount > 2000 then
Exit(LS_CLICKPLAY);
Result := LS_LOGGEDOUT;
end;
function isLoggedIn() : Boolean;
begin
Result := GetLoginState() = LS_LOGGEDIN;
end;
function isWorldScreen() : Boolean;
begin
Result := GetLoginState() = LS_WORLDSELECT;
end;
function isPlayScreen() : Boolean;
begin
Result := GetLoginState() = LS_CLICKPLAY;
end;
function GetLoginScreen() : Integer;
var
yellowCount : Integer;
begin
yellowCount := CountColor(YELLOW_TEXT, CX1, CY1, CX2, CY2);
if yellowCount = 479 then
Exit(0); //Welcome screen
if (yellowCount = 210) or (yellowCount = 439) then
Exit(1); //Warning screen
if (yellowCount = 1037) or (yellowCount = 1061) then
Exit(2); //Credentials screen
end;
function isWelcomeScreen() : Boolean;
begin
Result := GetLoginScreen = LS_WELCOME;
end;
function isWarningScreen() : Boolean;
begin
Result := GetLoginScreen = LS_WARNING;
end;
function isCredsScreen() : Boolean;
begin
Result := GetLoginScreen = LS_CREDS;
end;
Any help appreciated!