• 🏆 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] 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
 
Level 26
Joined
Mar 19, 2008
Messages
3,140
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