• 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] Do I need to null these locals?

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
JASS:
function example takes nothing returns nothing
    local unit u
    local real r
    local integer i
    if check == true then
        set u = GetAttacker()
        set r = 1.50
        set i = 2
        //do actions....
        set u=null
    endif
endfunction

Do I need to null the unit variable "u" outside of the "if" condition? I mean if "check == false", do i still need to null the unit variable "u"? Such as the following:
JASS:
function example takes nothing returns nothing
    local unit u
    local real r
    local integer i
    if check == true then
        set u = GetAttacker()
        set r = 1.50
        set i = 2
        //do actions....
        set u=null
    endif
    set u = null // do i need this? I dont think so but Im not sure...
endfunction
 
Additionaly, remember that you need only to null handle locals, leave integrals, reals and booleans alone.

If you respond to handle like unit via GetTriggeringUnit() (or similar getters) just up to 2 times, you can actually omit declaring local variable and use that getter instead. Cost of delaring local, initializing it and nulling is similar to one when 2 calls are performed.
Of course, this is also a matter of taste and your personal workflow preference.
 
Level 11
Joined
Oct 11, 2012
Messages
711
No, only if it was initialized. Like this:
JASS:
local unit u = GetAttacker()

Additionaly, remember that you need only to null handle locals, leave integrals, reals and booleans alone.

If you respond to handle like unit via GetTriggeringUnit() (or similar getters) just up to 2 times, you can actually omit declaring local variable and use that getter instead. Cost of delaring local, initializing it and nulling is similar to one when 2 calls are performed.
Of course, this is also a matter of taste and your personal workflow preference.

Aight, thnx both of you. :)
 
Status
Not open for further replies.
Top