• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[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,243
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