SRL Archive - SRL Archives

WaitFunc Modification


Bad Boy JH

2010-02-24 03:40:37

This makes the WaitFunc wait until the function is either true or false depending on what the scripter wants.

function WaitFunc(Func: Function: Boolean; WaitPerLoop, MaxTime: Integer; WaitTrue:Boolean): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) do
begin
if (Func()) xor Not(WaitTrue) then
begin
Result := True;
Exit;
end;
Wait(WaitPerLoop);
end;
end;

Baked0420

2010-02-24 05:56:03

I never saw the coding to that function, so I never knew how to make a function be a parameter, that's pretty cool, I wanna try making a function that calls a function.

And what did the old function look like? Just wondering how the two look in comparison with eachother.

Bad Boy JH

2010-02-24 06:31:29

the
if (func()) xor not(WaitTrue) then
Was actually just….
if (func()) then
small mod ,but allows for variety of extra things…
ALSO would this have too many issues, ie

Sir R. M8gic1an

2010-02-24 08:09:27

http://villavu.com/forum/showthread.php?t=46915


{*******************************************************************************
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
//to implement this idea...
if (Func() = WaitTrue) then
//if (Func()) then
begin
Result := True;
Exit;
end;
Wait(WaitPerLoop);
end;
end;

I like the idea, it'll most likely be implemented, only differently.

~RM