HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Solution to loop waits

09-19-2004, 09:57 PM#1
Beta_Tester
I have figured out how to make a wait in a loop without it making it longer

put this in your custom script and call it whenever you want to wait in a loop:
Code:
function LoopWait takes real r returns nothing
    call PolledWait( r )
endfunction

to use it do something like this:
Code:
loop
    exitwhen i > 11
    call DisplayToPlayer( player(0), "This is a loop wait - " + I2S( i ))
    call LoopWait( 0.25 )
endloop
09-19-2004, 10:11 PM#2
Extrarius
And just calling PolledWait directly doesn't work?
09-19-2004, 11:36 PM#3
weaaddar
except that doesn't really work right, as the minimal thread sleep time is around .25 s.

Really if you want to do a loop wait just have a timer constantly launch and store everything on the timer until the condition is met.
For instance let say I want to print how long a timer has been running every 10th of a second for 5 seconds I would do something like this
function H2I takes handle h returns integer
return h
return 0
endfunction
function I2T takes integer i returns timer
return i
return null
endfunction

function HowLong takes nothing returns nothing
local gamecache gc=InitGameCache("gc.w3v")
local timer t
local timer expirer
if(GetExpiredTimer()==null)then //both timers don't exist
set t=CreateTimer()
set expirer=CreateTimer()
call StartTimer(expirer,5,false,null)
call StoreInteger(gc,I2S(H2I(expirer)),"M_t",H2I(t))
else
set expirer=GetExpiredTimer()
set t=I2T(GetStoredInteger(gc,I2S(H2I(expirer)),"M_t"))
endif
if(GetElapsedTime(t)>=5)then
call DestroyTimer(t)
call DestroyTimer(expirer)
endif
call BJDebugMsg(R2S(GetElapsedTime(t) ) )
call TimerStart(expirer,0.1,false,function HowLong)
endfunction
This is obviously a very stupid example. But it works and shows that the triggersleepaction while a hell of a lot more convient can be replaced.