SRL Archive - SRL Suggestions

WaitGameTab


Hobbit

2011-01-22 19:47:32


{*******************************************************************************
function WaitGameTab(Tab: Integer; Time: Integer): Boolean;
By: Hobbit
Description: Waits for a specified GameTab, returns true if found
*******************************************************************************}

function WaitGameTab(Tab: Integer; Time: Integer): Boolean;
var
T: Integer;
begin
Result := false;
T := GetSystemTime + Time;
while (GetSystemTime < T) do
begin
if (GetCurrentTab = Tab)) then
begin
Result := True;
Exit;
end;
Wait(20 + Random(20));
end;
end;

{*******************************************************************************
function WaitGameTabExist(Tab: Integer; Time: Integer): Boolean;
By: Hobbit
Description: Waits for a specified GameTab to exist, returns true if found
*******************************************************************************}

function WaitGameTabExist(Tab: Integer; Time: Integer): Boolean;
var
T: Integer;
begin
Result := false;
T := GetSystemTime + Time;
while (GetSystemTime < T) do
begin
if (TabExists(Tab)) then
begin
Result := True;
Exit;
end;
Wait(20 + Random(20));
end;
end;


(Can't remember my SVN Password)

Second one would be useful for after a random is solved (As pointed out by Train)

marpis

2011-01-22 20:21:45

I don't see much use, except for after a random. You could also use "while InRandom do wait(10)" as well?

Gu3st...

2011-01-22 20:22:51

WaitFunc() anyone?

EDIT: Actually.. nevermind.. WaitFunc doesn't support parameters…
{*******************************************************************************
function WaitFunc(Func: Function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
By: Rasta Magician, small edit by EvilChicken!
Description: Waits for function Func to be true. WaitPerLoop is how often you
want to call "Func" function.
Example: "WaitFunc(@BankScreen, 10 + Random(15), 750);" will check if BankScreen
is open every 10-25th millisecond, for a maximum of 750 milliseconds.
Notice the '@'.
*******************************************************************************}
function WaitFunc(Func: function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func()) then
begin
Result := True;
Exit;
end;
Wait(WaitPerLoop);
end;
end;

EvilChicken!

2011-01-22 20:25:24

I don't really see the point of the first function? Waiting for the gametab to be selected is already implemented into Gametab(); ..

I'll commit the second function if you want to.

Hobbit

2011-01-22 22:00:10

I'm using it for an alcher.

So when alching RS automatically changes back to the spell tab after. I'm using it to control the waiting until it back at the spell tab.

Add it or not, it doesnt matter to me. Just thought it might be helpful to someone else.

TomTuff

2011-01-23 04:05:25

From: Zyt3x
WaitFunc() anyone?

EDIT: Actually.. nevermind.. WaitFunc doesn't support parameters…
{*******************************************************************************
function WaitFunc(Func: Function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
By: Rasta Magician, small edit by EvilChicken!
Description: Waits for function Func to be true. WaitPerLoop is how often you
want to call "Func" function.
Example: "WaitFunc(@BankScreen, 10 + Random(15), 750);" will check if BankScreen
is open every 10-25th millisecond, for a maximum of 750 milliseconds.
Notice the '@'.
*******************************************************************************}
function WaitFunc(Func: function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func()) then
begin
Result := True;
Exit;
end;
Wait(WaitPerLoop);
end;
end;



Dgby714 made one.


{*******************************************************************************
function WaitFuncEx(Func: string; var Args: TVariantArray; WaitPerLoop, MaxWait: integer): boolean;
By: Dgby714
Description: Calls Func with arguments Args every WaitPerLoop milliseconds
for a max of MaxWait milliseconds.
Func can return any basic types (boolean, string, integer).
boolean: Returns it.
string: Returns true if string equals 'true'.
integer: Returns true unless it equals 0.
*******************************************************************************}
function WaitFuncEx(Func: string; var Args: TVariantArray; WaitPerLoop, MaxWait: integer): boolean;
var
T: integer;
Temp: variant;
begin
T := GetSystemTime + MaxWait;
while (GetSystemTime < T) do
begin
Temp := CallProc(Func, Args);
if (not (VarType(Temp) = varString)) then
Temp := ToStr(Temp);
Result := StrToBoolDef(Temp, False);
if (Result) then
Exit;
Wait(WaitPerLoop);
end;
end;

Found in this thread.

Naike

2011-01-23 04:19:16

Both are useful?

It's sub functions that already should exist in gametab.scar!

Wizzup?

2011-01-23 04:36:10

Why exactly is this useful? This is IMO too trivial to be in SRL. Every scripter can make this himself.

EvilChicken!

2011-01-23 04:48:03

From: TomTuff
Dgby714 made one.


{*******************************************************************************
function WaitFuncEx(Func: string; var Args: TVariantArray; WaitPerLoop, MaxWait: integer): boolean;
By: Dgby714
Description: Calls Func with arguments Args every WaitPerLoop milliseconds
for a max of MaxWait milliseconds.
Func can return any basic types (boolean, string, integer).
boolean: Returns it.
string: Returns true if string equals 'true'.
integer: Returns true unless it equals 0.
*******************************************************************************}
function WaitFuncEx(Func: string; var Args: TVariantArray; WaitPerLoop, MaxWait: integer): boolean;
var
T: integer;
Temp: variant;
begin
T := GetSystemTime + MaxWait;
while (GetSystemTime < T) do
begin
Temp := CallProc(Func, Args);
if (not (VarType(Temp) = varString)) then
Temp := ToStr(Temp);
Result := StrToBoolDef(Temp, False);
if (Result) then
Exit;
Wait(WaitPerLoop);
end;
end;

Found in this thread.


Just a bit off-topic, but I feel it's important – has this been tested and does this work with all varTypes ect.?

If so, I'll just commit this and our problem will be solved here, no?

TomTuff

2011-01-23 05:01:53

From: EvilChicken!
Just a bit off-topic, but I feel it's important – has this been tested and does this work with all varTypes ect.?

If so, I'll just commit this and our problem will be solved here, no?


No, but I was going to start a script to get my magic up and it would use this. Can I get back to you on this tomorrow?

EvilChicken!

2011-01-23 07:03:24

From: TomTuff
No, but I was going to start a script to get my magic up and it would use this. Can I get back to you on this tomorrow?


That would be really nice!
Send me a PM or somthing. :)

Hobbit

2011-01-23 10:49:40

From: Wizzup?
Why exactly is this useful? This is IMO too trivial to be in SRL. Every scripter can make this himself.


Well theres like 10 other wait things in SRL that a scripter could make themselves?


I was just posting because I thought maybe it'd be helpful.

Wizzup?

2011-01-24 14:38:35

From: Hobbit
Well theres like 10 other wait things in SRL that a scripter could make themselves?


I was just posting because I thought maybe it'd be helpful.


Then they will be removed. :)

Gu3st...

2011-01-24 14:52:55

From: Wizzup?
Then they will be removed. :)
Are you serious?

It's used in like every script around nowadays, and MSI too uses it.

Wizzup?

2011-01-24 17:23:23

From: Zyt3x
Are you serious?

It's used in like every script around nowadays, and MSI too uses it.


Well, they are rather pointless aren't they? It's obviously not (just) up to me, but I don't see the purpose. :p

Gu3st...

2011-01-24 17:25:50

From: Wizzup?
Well, they are rather pointless aren't they? It's obviously not (just) up to me, but I don't see the purpose. :p
Instead of doing Wait(500); GameTab(tab_Inv); you can do WaitGameTab(tab_Inv, 100, 500);

the first waits 500ms no matter what, but the second waits 100ms for each time GameTab fails

Imo not pointlessa at all :) Pretty useful actually

**BANNED The Man

2011-01-24 17:29:07

From: Wizzup?
Then they will be removed. :)


I don't think they should now be removed BUT, I have to agree that why are such simple functions being added to SRL… Soon a "scripter" will just have to do:
program Script;
{$i srl/AllTheFunctionsYouCouldEverNeed.simba}

begin
WalkVEMine;
Mine;
WalkBank(VEB);
Bank(All);
end.

My 2 cents.

-Boom

pyroryan

2011-01-24 19:20:24

From: Dynamite
I don't think they should now be removed BUT, I have to agree that why are such simple functions being added to SRL… Soon a "scripter" will just have to do:
program Script;
{$i srl/AllTheFunctionsYouCouldEverNeed.simba}

begin
WalkVEMine;
Mine;
WalkBank(VEB);
Bank(All);
end.

My 2 cents.

-Boom


WalkVEMine would be insane and symbolize an large number of unnecessary procedures, especially since it would not be used a lot. More like WalkTo(VEMINE) or something to that effect may be more used. Even then, VEMINE constant shouldn't be there.

TomTuff

2011-01-24 19:37:37

From: EvilChicken!
That would be really nice!
Send me a PM or somthing. :)


WaitFuncEx didn't work very well, at least not with FindTextTPA.

From: Wizzup?
Then they will be removed. :)


Shouldn't be done.

Wanted

2011-01-24 20:22:49

WaitFuncEx and WaitFunc seems useful, but WaitGameTab seems redundant. The only reason we have WaitText etc. is because if we didn't, they are so common every script would have loops for text or look like WaitFuncEx(@IsUpTextMulit([///

Train

2011-01-24 22:27:57

From: IceFire908
WaitFuncEx and WaitFunc seems useful, but WaitGameTab seems redundant. The only reason we have WaitText etc. is because if we didn't, they are so common every script would have loops for text or look like WaitFuncEx(@IsUpTextMulit([///


They wouldn't fix in Antirandoms.scar, for waiting for your player to get out of the random? I thought they would.

jannypan

2011-04-13 04:57:07

They wouldn't fix in Antirandoms.scar, for waiting for your player to get out of the random? I thought they would.