SRL Archive - SRL Archives

Re-organized BankScreen for faster result


NCDS

2010-01-20 19:42:16

For comparison I timed each function 5 times.

Five tries with Current BankScreen:

102
137
104
131
117
5 tries with re-organized BankScreen:

8
15
18
13
37
All I did was make the function check for the result first so it doesn't get held up on the filasafes if it doesn't need to.

Re-organized version:

{*******************************************************************************
function BankScreen: Boolean;
by: NCDS, Coh3n, Sabzi, nielsie95, and Timer
Description: Finds Bankscreen. Returns true if Found.
*******************************************************************************}
function BankScreen: Boolean;
var
c: Integer;
begin
c := GetTimeRunning + 5000;
repeat
Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
if Result then
Exit;
Wait(50);
until ((GetTimeRunning > c));
Wait(RandomRange(100, 150));
end;
Doesn't it make more sense to have it this way?

Coh3n

2010-01-20 23:14:37

From: NCDS
Doesn't it make more sense to have it this way?

Yes it does. What's with all the CountColor and MouseBox mumbo jumbo? Can't you just have it wait until the text is found or timed out?

NCDS

2010-01-21 00:46:08

I thought about all that too, it's in there from the previous BankScreen function. I'm assuming it checks for BlackScreen for SMART users?

Coh3n

2010-01-21 11:31:09

From: NCDS
I thought about all that too, it's in there from the previous BankScreen function. I'm assuming it checks for BlackScreen for SMART users?

Again, you could just use a while..do statement to wait for the screen, otherwise it times out, and therefore can't find the screen. Seems much easier to me.

NCDS

2010-01-21 16:03:58

From: Coh3n
Again, you could just use a while..do statement to wait for the screen, otherwise it times out, and therefore can't find the screen. Seems much easier to me.


Fixed to that ^.

Coh3n

2010-01-21 16:13:08

See, now that makes much more sense to me. :p

NCDS

2010-01-21 16:16:37

From: Coh3n
See, now that makes much more sense to me. :p


I agree.

Seems no one else has an opinion..?

nielsie95

2010-01-21 16:30:42

Isn't this a possible infinite loop?

Coh3n

2010-01-21 16:33:10

That's what the GetSystemTime < c is for, I think.

nielsie95

2010-01-21 16:34:28

The problem is that the c is constantly set, because Bankscreen gets called over and over again.

Sabzi

2010-01-21 16:35:38

From: Coh3n
That's what the GetSystemTime < c is for, I think.


Yeah, but when you call the function again won't it start a new one again and again? I don't really know how these recursive things work but it seems like that it can be infinitive for me too.

:ninja:'d, but he knows is better :redface:

Coh3n

2010-01-21 16:35:50

From: nielsie95
The problem is that the c is constantly set, because Bankscreen gets called over and over again.

Oh, then shouldn't it be while (not Result)…

Timer

2010-01-21 16:36:38

function BankScreen: Boolean;
var
c: Integer;
begin
Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
if (Result) then
Exit;
c := GetTimeRunning + 45000;
while (not FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing)) and (GetTimeRunning < c) do
Wait(50);
Wait(RandomRange(100, 150));
end;
Now it doesn't?

EDIT:
function BankScreen: Boolean;
var
c: Integer;
begin
if (FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing)) then
Exit;
c := GetTimeRunning + 45000;
while (not FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing)) and (GetTimeRunning < c) do
Wait(50);
Result := GetTimeRunning < c;
//Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
Wait(RandomRange(100, 150));
end;

Gu3st...

2010-01-21 16:37:16

Yeah, there is no infinite loops there
E: Wow sorry, didn't see the (not BankScreen)

Coh3n

2010-01-21 16:37:47

@Timer: What I said above. ;)

Sabzi

2010-01-21 16:39:08

function BankScreen: Boolean;
var
c: Integer;
begin
c := GetTimeRunning + 45000;
repeat
Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
if Result then
Exit;
Wait(50);
until Result and (GetTimeRunning > c)
Wait(RandomRange(100, 150));
end;

Me too! Actually there is no need for Result check in the until because it will just exit before anyway.

EDIT: I ninja'd back?

nielsie95

2010-01-21 16:39:12

From: Coh3n
Oh, then shouldn't it be while (not Result)…


No, because you never set the result in the loop. If you call a function from itself, it doesn't start over again, it's the same as every other call.

Timer's function is right, but you need to set the result too.

EDIT: Sabzi, you need to ditch the "until Result", because result will never be true there (so that's an infinite loop too).

Coh3n

2010-01-21 16:40:47

From: nielsie95
No, because you never set the result in the loop. If you call a function from itself, it doesn't start over again, it's the same as every other call.

Timer's function is right, but you need to set the result too.

Oh yeah, you're right. :p

Timer

2010-01-21 16:41:50

From: Sabzi
function BankScreen: Boolean;
var
c: Integer;
begin
c := GetTimeRunning + 45000;
repeat
Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
if Result then
Exit;
Wait(50);
until Result and (GetTimeRunning > c)
Wait(RandomRange(100, 150));
end;

Me too!

No need for
if Result then
Exit;
AND
until Result and (GetTimeRunning > c)

would have to be
function BankScreen: Boolean;
var
c: Integer;
begin
c := GetTimeRunning + 45000;
repeat
Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
Wait(50);
until (Result or (GetTimeRunning > c));
Wait(RandomRange(100, 150));
end;
or
function BankScreen: Boolean;
var
c: Integer;
begin
c := GetTimeRunning + 45000;
repeat
Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
if Result then
Exit;
Wait(50);
until ((GetTimeRunning > c));
Wait(RandomRange(100, 150));
end;

Sabzi

2010-01-21 16:43:32

@Timer: Wahaha so funny while I write or edit a post there is 2 more post already. I have already found that out. But I wanted to post the first version fast XD.

NCDS

2010-01-21 17:08:49

Wow, this thread blew up..

Updated first post to the version Timer posted. I chose the one I did because this one will exit immediately after Result returns true instead of waiting, then exiting.

Timer

2010-01-21 17:11:18

From: Timer
function BankScreen: Boolean;
var
c: Integer;
begin
if (FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing)) then
Exit;
c := GetTimeRunning + 45000;
while (not FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing)) and (GetTimeRunning < c) do
Wait(50);
Result := GetTimeRunning < c;
//Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
Wait(RandomRange(100, 150));
end;


Is better, I say.

NCDS

2010-01-21 17:14:43

From: Timer
Is better, I say.


it never set's the Result though if it finds then BankScreen on first check?

Timer

2010-01-21 17:15:50

From: NCDS
it never set's the Result though if it finds then BankScreen on first check?


Oh. There…
function BankScreen: Boolean;
var
c: Integer;
begin
Result := True;
if (FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing)) then
Exit;
c := GetTimeRunning + 45000;
while (not FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing)) and (GetTimeRunning < c) do
Wait(50);
Result := GetTimeRunning < c;
//Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);
Wait(RandomRange(100, 150));
end;

NCDS

2010-01-21 17:51:05

I think the one I picked already has the least repetitive/smoothest flowing code.

Timer

2010-01-21 17:55:45

We completely kinda re-wrote it. Not trying to be a credit hoar. Shouldn't it be something like this though?

by: NCDS, Coh3n, Sabzi, nielsie95, and Timer

NCDS

2010-01-21 18:00:32

From: Timer
We completely kinda re-wrote it. Not trying to be a credit hoar. Shouldn't it be something like this though?

by: NCDS, Coh3n, Sabzi, nielsie95, and Timer


Fixed that too ;)

Timer

2010-01-21 18:04:29

From: NCDS
Fixed that too ;)


I wish we were all Devs. :<

Wanted

2010-01-21 18:10:29

Waiting 45 seconds if the bankscreen isn't open.

No thanks.

NCDS

2010-01-21 18:13:33

From: IceFire908
Waiting 45 seconds if the bankscreen isn't open.

No thanks.


I thought that too when I read it but assumed it was left from the previous function. I think a 5 second wait would suffice.

Wanted

2010-01-21 18:20:28

Now honestly, I haven't had any problems with BankScreen in two years. Is this really necessary to tinker with stuff if it's working fine to get 100 ms out of something that isn't even used in a loop? I mean if you need to optimize it that bad then make a BankScreen2 in your script. Comon.

NCDS

2010-01-21 18:31:16

From: IceFire908
Now honestly, I haven't had any problems with BankScreen in two years. Is this really necessary to tinker with stuff if it's working fine to get 100 ms out of something that isn't even used in a loop? I mean if you need to optimize it that bad then make a BankScreen2 in your script. Comon.


I'm not forcing anyone to add this to the SRL include. I simply pointed out that this way is faster and am leaving the rest up to the public and dev's.

I see nothing wrong with that.

Doesn't it also make sense though to keep our include running as fast and efficient as possible?

Wanted

2010-01-21 18:37:38

Bankscreen is really stable right now, so why even bother messing with it? What are you going to do with an excess of 150ms? It usually takes the bankscreen around that time to load your items after the text appears anyways. Even if you could add the 150 ms excess to the actual script efficiency time the average script does 30 trips per an hour so you save 3 seconds an hour. Great.

NCDS

2010-01-21 18:44:51

I don't see why this frustrates you so much. Is this not what this section of the forums are for?

There is no need to continue to "debate" this. I did my part by bringing this to everyone's attention. Whatever happens now is up to everyone else. That's that.

Timer

2010-02-13 03:25:51

Bump.

I suggest this is implanted, as current BankScreen always gives false positives.

Gu3st...

2010-02-13 03:38:05

From: Timer
Bump.

I suggest this is implanted, as current BankScreen always gives false positives.
If this doesn't give false positives then I agree :)

Wanted

2010-02-13 13:31:33

This will not help prevent false positives, it uses the same argument for results.

"Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);"

The current bankscreen will exit immediately if a suspected bankscreen is not open hence the looping is done after a color check

"if (CountColor(0, MSX1, MSY1, MSX2, MSY2) > 113000) then"

The one suggested here will always wait 5+ seconds if the bankscreen is not up.

I don't think everyone wants to wait 5+ seconds if the bankscreen is not up. This isn't exactly the kinda thing you want to be universal in every script that uses SRL.

If you still have problems with the current one (which I don't) then I suggest you find another solution(suggested fix) or make a "BankScreen2" for one that fits your current purpose better.

NCDS

2010-02-13 14:03:55

From: IceFire908
This will not help prevent false positives, it uses the same argument for results.

"Result := FindTextTPA(4106994, 20, 20, 22, 400, 45, 'Bank', upchars, Nothing);"

The current bankscreen will exit immediately if a suspected bankscreen is not open hence the looping is done after a color check

"if (CountColor(0, MSX1, MSY1, MSX2, MSY2) > 113000) then"

The one suggested here will always wait 5+ seconds if the bankscreen is not up.

I don't think everyone wants to wait 5+ seconds if the bankscreen is not up. This isn't exactly the kinda thing you want to be universal in every script that uses SRL.

If you still have problems with the current one (which I don't) then I suggest you find another solution(suggested fix) or make a "BankScreen2" for one that fits your current purpose better.


Could you please explain this:

MouseBox(26, 138, 489, 157, 1);
in the current BankScreen function? I've wondered about that for a while now.

I don't like the current BankScreen function honestly, but it has been working fine for me lately.

Wanted

2010-02-13 14:13:01

From: NCDS
Could you please explain this:

MouseBox(26, 138, 489, 157, 1);
in the current BankScreen function? I've wondered about that for a while now.

I don't like the current BankScreen function honestly, but it has been working fine for me lately.


It's been like this since OpenDev Rev 1, ask Wizzup I guess