Warcraft III resources & community, 2003–2006 · archived

jass is driving me insane(need some help)

5 posts
#1

jass is driving me insane(need some help)

Hello again,

im still trying to make handles work in ROC and here's the next issue.
I copied the handle script into blizzard.j, thx to low-life for that suggestion.
The awesome thing is that WE actually accepts my scripts with handle functions in it
now, it doenst crash or give erros! wooohhaaaa!!!

But...the script doenst execute. It is meant to display a message to me when i kill a unit but that just doesnt happen. The script looks good to me, no syntax errors.

      
function text takes nothing returns nothing
    local string A = "omg u killed"
    local timer t = CreateTimer()
    local unit killer = GetHandleUnit(t,"testing")
    local unit d = GetHandleUnit(t,"tester")
    local string B = GetUnitName(d)
    call DisplayTimedTextToPlayer(GetOwningPlayer(killer),0,0,500,"A+B")
    set killer = null
    set d = null
    set A = null
    set B = null
    call DestroyTimer(t)
endfunction

function Trig_handletesting_Actions takes nothing returns nothing
    local unit killer = GetKillingUnit()
    local unit dieer = GetTriggerUnit()
    local timer t = CreateTimer()
    call SetHandleHandle(t,"testing",killer)
    call SetHandleHandle(t,"tester",dieer)
    call TimerStart(t,10,false,function text)
    set killer = null
    set dieer = null
    call DestroyTimer(t)
    call FlushHandleLocals(t)
    
endfunction

//===========================================================================
function InitTrig_handletesting takes nothing returns nothing
    set gg_trg_handletesting = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_handletesting, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_handletesting, function Trig_handletesting_Actions )
endfunction



Does anyone have a clue why this is the case?

thanks,
frenksel
#2
Cause you destroy the timer right after you start running it?

The timer call doesnt pause the calling function, or everyone would just use it as a substitute for Wait.

Anyways, another few notes

-You didnt null the timer in either func
-You cant FlushHandleLocals after you DestroyTimer ( as far as i know )
#3
local timer t = CreateTimer()
should be
local timer t = GetExpiredTimer()
#4
Lolz, that too, if you actually wish to recieve any handle data
#5
function text takes nothing returns nothing
    local timer t = GetExpiredTimer()
    call DisplayTimedTextToPlayer(GetOwningPlayer(GetHandleUnit(t,"testing")),0,0,500,"omg u killed "+GetUnitName(GetHandleUnit(t,"tester")))
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set t = null
endfunction
 
function Trig_handletesting_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    call SetHandleHandle(t,"testing",GetKillingUnit())
    call SetHandleHandle(t,"tester",GetTriggerUnit())
    call TimerStart(t,10,false,function text)
    set t = null
endfunction

function InitTrig_handletesting takes nothing returns nothing
    set gg_trg_handletesting = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_handletesting, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_handletesting, function Trig_handletesting_Actions )
endfunction


Ok this should work with 0 leaks.
As you can see I restructured the locals for effiency and repaired the script so that is should work.

The main problem was you were not handling your timer correctly so look at the corrections and learn.

Also I removed some of the locals so that they are more efficent and as far as I know do not leak.
I have not actualy tested this script but hopefully it should work.