HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Lost Data?

07-04-2009, 08:35 PM#1
Joker
Somehow, the dat.aa becomes null and I'm almost certain the problem is not with TimerUtils. Bugs with both 1.24 and 1.23b.
Collapse JASS:
scope RoadKill initializer Init

    globals
        private constant real INTERVAL  = 0.1
        private constant real AOE       = 275.
    endglobals
    //=================================================================
    
    private struct Road
        unit aa
        timer t
        static unit Pass

        private method onDestroy takes nothing returns nothing
            call ReleaseTimer( .t )
            call GroupRefresh( ENUM_GROUP )
        endmethod
        
        private static method Ground takes nothing returns boolean
            return IsAlive( GetFilterUnit() ) and GetFilterUnit() != Road.Pass
        endmethod
        
        private static method Callback takes nothing returns nothing
            local Road dat = GetTimerData( GetExpiredTimer() )
            call BJDebugMsg(GetUnitName(dat.aa)) //this shows (null)
            if IsAlive( dat.aa ) then
                call BJDebugMsg("run")
                set Road.Pass = dat.aa
                call GroupEnumUnitsInRange( ENUM_GROUP, GetUnitX( dat.aa ), GetUnitY( dat.aa ), AOE, Condition( function Road.Ground ) )
                call UnitDamageTarget( dat.aa, FirstOfGroup( ENUM_GROUP ), 99999, false, true, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS ) 
            else
                call BJDebugMsg("end")
                call dat.destroy()
            endif
        endmethod
        
        static method startKilling takes unit a returns Road
            local Road dat = Road.allocate()
            
              set dat.aa = a
              set dat.t = NewTimer()
            call BJDebugMsg(GetUnitName(dat.aa)) //this actually shows the name
            call SetTimerData( dat.t, dat )
            call TimerStart( dat.t, INTERVAL, true, function Road.Callback )
            return dat
        endmethod
    endstruct
    //=================================================================
    
    private function Actions takes nothing returns nothing
        call Road.startKilling( GetTriggerUnit() )
    endfunction
    
    private function Conditions takes nothing returns boolean
        return GetUnitAbilityLevel( GetTriggerUnit(), 'A007' ) > 0
    endfunction

    private function Init takes nothing returns nothing
        call UnitEnterEvent( Condition( function Conditions ), function Actions, bj_mapInitialPlayableArea )
    endfunction
    
endscope
07-04-2009, 09:10 PM#2
Troll-Brain
Maybe it happens when the unit is removed by the function RemoveUnit or when the unit is removed by the game (end of decay, some abilities like finger of death, explode unit, etc ...) ?
07-04-2009, 09:11 PM#3
Joker
No, i'm certain there are no outside influences. I never ever see the "run" msg.
07-04-2009, 09:13 PM#4
Troll-Brain
Quote:
Originally Posted by Joker
No, i'm certain there are no outside influences. I never ever see the "run" msg.
Actually it depends how the function IsAlive is written.
07-04-2009, 09:20 PM#5
Joker
Collapse JASS:
library IsAlive

    function IsAlive takes unit a returns boolean
        return GetWidgetLife( a ) > 0.406 
    endfunction

endlibrary

EDIT: What the hell. It simply doesn't work on preplaced units. I created a unit ingame and it worked.
07-04-2009, 09:49 PM#6
Blubb-Tec
Quote:
Originally Posted by Joker
Collapse JASS:
library IsAlive

    function IsAlive takes unit a returns boolean
        return GetWidgetLife( a ) > 0.406 
    endfunction

endlibrary

EDIT: What the hell. It simply doesn't work on preplaced units. I created a unit ingame and it worked.

i guess this will then be because your event runs at map init, and therefor bugs with struct/libtrary initializers. simply make it run after a 0.0 timer, that should solve.
07-05-2009, 11:08 AM#7
Troll-Brain
Preplaced units are created before any initializer but you can enum them.

Also it's > 0.405
07-06-2009, 12:28 AM#8
darkwulfv
Quote:
Also it's > 0.405
Or IsUnitType(u, UNIT_TYPE_DEAD)
07-06-2009, 03:43 PM#9
Troll-Brain
Quote:
Originally Posted by darkwulfv
Or IsUnitType(u, UNIT_TYPE_DEAD)

Personally i use also this one, i don't care about the performance "issue", it should be safer, but i remember that Vexorian thought it isn't.
07-06-2009, 08:17 PM#10
Bobo_The_Kodo
Quote:
but i remember that Vexorian thought it isn't.
Because it fails on removed units ... But that hardly matters for things like instant enumeration. If you want to be safe, you can put, IsUnitType( u, UNIT_TYPE_DEAD ) or GetUnitTypeId( u ) == 0
07-06-2009, 08:20 PM#11
Troll-Brain
I see, thx.