• 🏆 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] Quick Function question.

Status
Not open for further replies.
Level 5
Joined
Sep 19, 2006
Messages
152
I'm pretty new to using takes/returns functions, so I have a silly question. In the proceeding function, does "trig_unit" need to be nulled?

JASS:
function PlayerUnitDeathHero_RevivalTimerFunction takes unit trig_unit, integer trig_unitQ, integer R returns nothing
    local integer  n             = (udg_PlayerScore [trig_unitQ] / 2500) + R
    local real     m             = (I2R (n) * udg_RealArray [trig_unitQ + 200]) + udg_RealArray [trig_unitQ + 140]
    local unit     u             = CreateUnit (Player (trig_unitQ), 'hsor', GetUnitX (trig_unit), GetUnitY (trig_unit), 0.00)

    set udg_PlayerRezWait [trig_unitQ] = R2I (m)
    call UnitApplyTimedLife (u, 'BTLF', m)
    set u = null
endfunction
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Nulling is done because you don't want to make a variable point to an object when you don't need to access the object anymore.

Variables hold information, the memory address of where data is. Nulling a variable is erasing that information, erasing the address.

With locals, we are creating them all the time as the code is run again and again. We can't allow unneeded data to pile up, therefore locals need to be nulled.

Globals do not need to be nulled since you are most likely going to be using the same variable again, making them point to other objects. The pointer information is overwritten.
 
Status
Not open for further replies.
Top