• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] [HELP] LoadUnitHandle does not work

Status
Not open for further replies.
Level 2
Joined
Nov 29, 2011
Messages
3
i'm having problem with LoadUnitHandle, why it does not work?


JASS:
function CallBack takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = LoadUnitHandle(udg_kbhs, GetHandleId(t), 0)
call KillUnit(u)
call BJDebugMsg("!")
endfunction

function SHActions takes nothing returns nothing
    local unit c
    local timer tm
    if ( GetSpellAbilityId() == 'Iky0' ) then
        set c = GetTriggerUnit()
        set tm = CreateTimer()
        call SaveUnitHandle(udg_kbhs, GetHandleId(tm), 0 , c)
        call TimerStart(tm,5,false,function CallBack)
    endif
endfunction

function InitTrig_SH takes nothing returns nothing
    local trigger b = CreateTrigger ()
    call TriggerRegisterAnyUnitEventBJ( b, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( b, function SHActions )
    set b = null
endfunction
 
Level 2
Joined
Nov 29, 2011
Messages
3
yes, here the trigger of hashtable initialization
JASS:
function initUnitsSoulHandlerActions takes nothing returns nothing

    call InitHashtable()
    set udg_kbhs = GetLastCreatedHashtableBJ()

endfunction


function InitTrig_HS takes nothing returns nothing
    local trigger c = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( c, 0.01 )
    call TriggerAddAction( c, function initUnitsSoulHandlerActions )
    set c = null
endfunction
 
Also this:
JASS:
function CallBack takes nothing returns nothing
    call KillUnit( LoadUnitHandle(udg_kbhs, GetHandleId(GetExpiredTimer()), 0) )
    call BJDebugMsg("!")
    call DestroyTimer(GetExpiredTimer())
endfunction
Otherwise your code leak.
And this:
JASS:
call TriggerRegisterTimerEvent( c, 0.01, false)
//native TriggerRegisterTimerEvent takes trigger whichTrigger, real timeout, boolean periodic returns event

And finally here:
JASS:
cafunction SHActions takes nothing returns nothing
    local timer tm
    if ( GetSpellAbilityId() == 'Iky0' ) then
        set tm = CreateTimer()
        call SaveUnitHandle(udg_kbhs, GetHandleId(tm), 0 , GetTriggerUnit())
        call TimerStart(tm, 5, false, function CallBack)
    endif
endfunction

Btw you don't need hashtables and timers here at all, this will do just fine:
JASS:
function SHActions takes nothing returns nothing
    if ( GetSpellAbilityId() == 'Iky0' ) then
        call TriggerSleepAction(5.)
        call KillUnit(GetTriggerUnit())
        call BJDebugMsg("!")
    endif
endfunction

function InitTrig_SH takes nothing returns nothing
    local trigger t = CreateTrigger ()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( t, function SHActions )
    set t = null
endfunction

If you use TriggeringUnit()/EnumUnit() and so on, only once or 2 times there is no need for local variables.

Oh 1 last thing your ability Id is 'Iky0', because it's item ability right? Try to make it unit ability and test trigger then.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
The short answer to your problem is you are not initializing the hashtabe.
The native does not set the BJ when it creates a new hashtable, only the BJ does that.

You will need to use code like Maker provided if you wish to use a hashtable as that way the variable gets set to a valid hashtable (and not some possibly null value).
 
Level 2
Joined
Nov 29, 2011
Messages
3
thanks pals, its already worked,
I suspected it was a problem with the initialization of the hashtable
I put a message saying the id of the unit during the callback and the unit's value was 0
lol, but now work ^^
 
Status
Not open for further replies.
Top