• 🏆 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!

[JASS] "code" type variable leak?

Status
Not open for further replies.
Level 3
Joined
Feb 25, 2010
Messages
25
Would be it leaks if I pass a 'code' type variable (which is a function) as a parameter to another function?

Ex:

JASS:
function DPS takes code c returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g,GetPlayableMapRect(),null)
    call ForGroup(g,c)
    call GroupClear(g)
    call DestroyGroup(g)
endfunction

function f takes nothing returns nothing
    call SetUnitLifeBJ(GetEnumUnit(),GetUnitState(GetEnumUnit(),UNIT_STATE_LIFE)-1)
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    call DPS(function f)
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_001, 0.01 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
 
Level 3
Joined
Feb 25, 2010
Messages
25
No, functions are static and function only denotes that the following identifier is a function and its pointer is wanted. No need to instantiate some object.

Ah... thanks for the answer, this makes my life easier
I thought it will form an object like TriggerAddAction? how it does (still curious)?
+rep

You should also optimize that code. Get rid of the BJs (red text functions) and never use TriggerAddAction use TriggerAddCondition and run everything from there.

IMO, some of BJs are lovely, ex: BJDebugMsg
I only use TriggerAddAction for trigger that stays permanently (does it still leaks? does it produce an object every time the action is executed?)
Anyways, it just an quick example, but thanks
 
Level 3
Joined
Feb 25, 2010
Messages
25
Well from your tutorial.. I took a conclusion that TriggerAddAction generates thread. As far as I know thread is subset of a process, how can it considered as object which is leak?

Looks like we go off-topic lol
 
Level 3
Joined
Feb 25, 2010
Messages
25
Ah.. so it recreates the function that already exist instead of using the current one?
Like function Trig_Untitled_Trigger_001_Actions?

Looks like I need more reference material on this
Could you lend me some?
I already tried to search it myself, but I didn't know the correct key to search, lol
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
TriggerAddCondition creates a thread as well. It's just faster, can return a boolean and has some other advantages like the destroy functions for triggeractions do not really deallocate the object, only deregister it from the trigger iirc. triggerconditions cannot have waits but those are rarely required. And no, contrary to the codes I read here all the time, returning from a triggercondition entry function is optional.
 
And no, contrary to the codes I read here all the time, returning from a triggercondition entry function is optional.

Returning a boolean isn't required by the standard editor or Wc3, but PJASS requires it (after PitzerMike updated it post 1.24 to address the return bug), which is why all the codes here return boolean in the callbacks.
 
Status
Not open for further replies.
Top