HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Delay in loop

05-07-2003, 04:16 PM#1
Mjukland
OK, ive made a function, lets say it looks like this

------------------------------------------------------------------------------------
function my_func takes nothing returns nothing
local integer i = 1
loop
exitwhen i > 30

( stuff that will happen )

set i=i+1
endloop

endfunction
------------------------------------------------------------------------------------

When i Do this, the stuff happens imidielitly, but I want a delay.

If i do this :

------------------------------------------------------------------------------------
function my_func takes nothing returns nothing
local integer i = 1
loop
exitwhen i > 30

( stuff that will happen )
call TriggerSleepAction( 0.01 )
set i=i+1
endloop

endfunction
------------------------------------------------------------------------------------
When I did this i thought the loop would be over in 0.3 sec but it looped much slower, it takes maybe 4-5 sec before its completed, is there any other way of making a delay in a loop without using the call TriggerSleepAction ??
05-07-2003, 07:14 PM#2
AIAndy
Well, you could put in a loop in the loop that just runs for a specific amount of loops each time.
If you need it to be more exact, you can use a timer at that point. Then just check in the inner loop if the timer already expired.
05-08-2003, 07:56 PM#3
Mjukland
Ok, Ive got it working now, i came around it by using 2 triggers and an if functions instead off a loop, well it is kind of a loop but not a loop function.

( dont know how the commands is right now, sitting on another computer but its something like this )

function twirl takes nothing returns nothing

if ( udg_IntTwirl < 30 ) then

BlaBlaBla ( stuff )
call exec timer( 0.02 sec , TwirlTimer )

else
BlaBlaBla ( stuff )
set udg_IntTwirl = 0

endif
endfunction

Then i got another trigger that checks when the timer expires,

event : timer TwirlTimer expires
actions: set udg_IntTwirl = udg_IntTwirl + 1
call trigger run (Twirl Function)

Now this stuff works, could probably do it in one trigger, but i couldnt realy figure it out so i did it the easy way. When i tested, the effect was kinda cool, the trigger is a spell thing and I by mistake, used a wrong variable.

The effect of the spell became that the unit affected whirled around the caster like 4-5 times and each time it looped around the caster , the affected unit was moved farer away from the caster, adding the cyclone effect to this made it look like the unit was thrown away in a whirlwind farer and farer away from the caster . =)

Well, its not a spell that would fit for a normal hero, im using it in a boss fight , so the area is controlled so a unit cant get moved in behind trees and get stuck.

You can check it out when we release a beta of our mod, soon I hope.

tnx for the help btw.