HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

2 Quick questions

12-28-2006, 10:37 AM#1
taste
1. is it possible to create a local timer that does nothing... sort of like a Wait action actually? i tried a making timer which callbacks 'DoNothing()' with a real of 2 seconds but it doesn't seem to work.

2 About timers... when exactly does the callback run? After the timeout or before the timeout?

3. I'm having abit of problem with this code.. if i takeout the pausetimer and releasetimer functions, it works perfectly but i'm to understand that it will be causing leaks? Is there something I'm doing wrong...

Collapse JASS:
function SpawnUnits takes nothing returns nothing
    local unit uLastCreatedUnit 
    local real DownDir = 270
    local real UpDir = 90
    local integer i = 1
    local integer j = 0
    local integer iUnitID = 'hpea'
    local timer t = GetExpiredTimer()
    loop
    exitwhen i > 10   
        //Check if too many units in the game Current Max 80
        if ( j >= 80 ) then    
            set i = 10
        endif
        call DisplayTextToForce( GetPlayersAll(), "loooop" )        
        call CreateNUnitsAtLoc( 1, 'hpea', Player(0), GetRandomLocInRect(gg_rct_Net), DownDir)
        set uLastCreatedUnit = GetLastCreatedUnit()
        call IssuePointOrderLocBJ( uLastCreatedUnit , "move", PolarProjectionBJ( GetUnitLoc(uLastCreatedUnit) , 10000.00, DownDir ))
        set uLastCreatedUnit = null

        call CreateNUnitsAtLoc( 1, 'hpea', Player(6), GetRandomLocInRect(gg_rct_Net), UpDir )
        set uLastCreatedUnit = GetLastCreatedUnit()
        call IssuePointOrderLocBJ( uLastCreatedUnit , "move", PolarProjectionBJ( GetUnitLoc(uLastCreatedUnit) , 10000.00, UpDir ))
        set uLastCreatedUnit = null
        set j = j + 2
        set i = i + 1
    endloop   
    
    call PauseTimer(t)    
    call ReleaseTimer(t)
    set t = null
endfunction

function Trig_Spawners2_Actions takes nothing returns nothing
    local timer GameTimer = NewTimer()
    call TimerStart(GameTimer,5, true, function SpawnUnits )
    set GameTimer = null
endfunction
12-28-2006, 02:18 PM#2
darkwulfv
1: If the timer is supposed to do the same thing as a wait, why not use the wait action?

2: I'm pretty sure the function is called when the timeout reaches 0 and reloops. (if it's a periodic)

3: Try DestroyTimer(t)... Unless ReleaseTimer(t) does something else to a timer, I've never seen nor used that function before.
12-28-2006, 02:24 PM#3
Vexorian
ReleaseTimer already pauses the timer so no need to pause the timer.

Timers won't stop your thread, you can wait till a timer expires, but that's actually pretty much what PolledWait(delay) does already.

I don't understand, when you add ReleaseTimer it doesn't work anymore? Don't you want the timer to be periodic? Then why would you want to release the timer? If you release the timer the timer is not going to expire on that function anymore, I don't think you want to do that cause you used true for the looping argument.

And you do have a lot of memory leaks:

Collapse JASS:
function SpawnUnits takes nothing returns nothing
    local unit uLastCreatedUnit 
    local real DownDir = 270
    local real UpDir = 90
    local integer i = 1
    local integer j = 0
    local integer iUnitID = 'hpea'
    local timer t = GetExpiredTimer()
    loop
    exitwhen i > 10   
        //Check if too many units in the game Current Max 80
        if ( j >= 80 ) then    
            set i = 10
        endif
        call DisplayTextToForce( GetPlayersAll(), "loooop" )        
        call CreateNUnitsAtLoc( 1, 'hpea', Player(0), GetRandomLocInRect(gg_rct_Net), DownDir)
        set uLastCreatedUnit = GetLastCreatedUnit()
        call IssuePointOrderLocBJ( uLastCreatedUnit , "move", PolarProjectionBJ( GetUnitLoc(uLastCreatedUnit) , 10000.00, DownDir ))
        set uLastCreatedUnit = null

        call CreateNUnitsAtLoc( 1, 'hpea', Player(6), GetRandomLocInRect(gg_rct_Net), UpDir )
        set uLastCreatedUnit = GetLastCreatedUnit()
        call IssuePointOrderLocBJ( uLastCreatedUnit , "move", PolarProjectionBJ( GetUnitLoc(uLastCreatedUnit) , 10000.00, UpDir ))
        set uLastCreatedUnit = null
        set j = j + 2
        set i = i + 1
    endloop   
    
    call PauseTimer(t)    
    call ReleaseTimer(t)
    set t = null
endfunction

function Trig_Spawners2_Actions takes nothing returns nothing
    local timer GameTimer = NewTimer()
    call TimerStart(GameTimer,5, true, function SpawnUnits )
    set GameTimer = null

callback runs after the timeout.
12-28-2006, 02:33 PM#4
taste
ops sry vexorian replied while i was posting

Thanks darkwulfv

just some things,

1. well, from some searching, the wait can be inaccurate, ie. minimum wait time is 0.27 i think

2. thanks

3. releasetimer works the same as destroytimer. i got it from vexorians spellcasting system.



----

Thanks Vexorian, I wasn't sure if i didn't release the timer it would cause leaks or not.

So if i set a timer to be periodic forever and ever in a map, i need release it, right?

Also, I didn't realize PolarProjection causes leaks. Just for that mater.. does this mean that ANY function that returns ANYTHING needs to be cleaned up otherwise it causes leaks? (just asking because i did read the other article about leaks and didn't remember seeing this point..)
12-28-2006, 02:57 PM#5
darkwulfv
As far as I know, Locations, rects, and groups are three returns that need to be cleaned. If a function creates something (like a location), it needs to be cleaned. Just set those to variables (local) and destroy and null them accordingly.

Well if you want your wait to be under .27 seconds, then sure, use a timer, but I don't know how to do that.

And thanks for mentioning the minimum on waits, it explains why my trigger is being stupid.
12-28-2006, 04:21 PM#6
taste
thanks alot that cleared some things up:)