SRL Archive - News and General

is it possible to interupt a wait procedure?


wantonman

2012-05-10 20:58:20

is it possible to interrupt a wait procedure? like if you have wait(10000);

what actions can you do to automatically stop this from reaching 10000?

Runaway

2012-05-10 21:43:59

You can use a while do loop:


while not(whatever) do
wait(1000);

That will wait indefinitely until whatever is true. Obviously you should put in failsafes and whatnot to make sure you don't get stuck in an infinite loop.

You can use repeat until loops as well to do the same thing:


repeat
wait(1000);
until(whatever);

Just remember that failsafes are necessary when using loops like these.

Sex

2012-05-10 21:46:07

No, you'll have to use loops like the above. I would recommend the while loop.

CephaXz

2012-05-10 21:47:06

It depends on what procedure you are doing. So what are you doing?

I'd recommend making a function then use WaitFunc, I personally think its more efficient.

wantonman

2012-05-10 22:23:50

even if you do jam it in a loop it still is actively counting to the number specified…

i dont think there is a way…

i tried

program new;


var
x:integer;
begin
ClearDebug
while x=0 do
begin
if iskeydown(16) then
break;
wait(10000);
if iskeydown(16) then
break;
end;
writeln('ggf')
end.



even by jamming a break loop trigger before and after the wait(); still nothing…


there should be a stopwait func…

Brandon

2012-05-10 22:30:42


var
SomeCondition: Boolean;



Function WaitSomething(TimeToWait: Integer): Boolean;
var
T: integer;
begin
Result:= False;
T := (GetSystemTime + TimeToWait);
while (GetSystemTime < t) do
begin
if (SomeCondition) then
begin
Result:= True;
Break;
end;
Wait(50);
end;
end;


The above will wait until SomeCondition is set to true.. if False, it will keep repeating some procedure/function until it times out OR until somecondition which can make it break out.

The problem would be setting somecondition. See you have to set it before running the function.. OR set it during the function in the while loop.

CephaXz

2012-05-10 22:31:10

Thats why I said it depends on what you are doing. WaitFunc is probably the best function I know as of now. It checks for the function every X time until the final time is reached. So

if waitfunc(@16keyisdown, 100, 10000) then
Exit;

It wait until the function is true, then break out of the wait.

Sex

2012-05-10 22:36:05

From: wantonman
even if you do jam it in a loop it still is actively counting to the number specified…

i dont think there is a way…

i tried

program new;


var
x:integer;
begin
ClearDebug
while x=0 do
begin
if iskeydown(16) then
break;
wait(10000);
if iskeydown(16) then
break;
end;
writeln('ggf')
end.



even by jamming a break loop trigger before and after the wait(); still nothing…


there should be a stopwait func…


Obviously you'll use a smaller wait not 10 seconds..