Arguments --> local or not?

wellwish3r

wishes wells.
Reaction score
52
I was just wondering when you pass arguments to a function are those arguments handled like locals, or do they get overwritten if the function is called again?
Does it depend if the variable that is used to pass the argument is a global or a local?
Do you have to Remove/Null/Destroy them if they are location,groups,....?
 

Flare

Stops copies me!
Reaction score
662
Arguments are local to the function, but handle-type arguments don't have to be nulled (I think)

Do you have to Remove/Null/Destroy them if they are location,groups,....?
Remove/Destroy? It depends - can you guarantee that the location won't be used elsewhere e.g.
JASS:
function MyFunc takes location l returns nothing
...
call RemoveLocation (l)
endfunction

function Test takes nothing returns nothing
local location loc = ...
call MyFunc (loc)
... //are you 100% sure that loc will never be used again below the MyFunc call?
endfunction

I'm fairly sure that will destroy loc correctly if you called RemoveLocation within MyFunc

Just to make certain, you should destroy locals in the same function in which they were declared i.e.
JASS:
function MyFunc takes location l returns nothing
...
endfunction

function Test takes nothing returns nothing
local location l = ...
call MyFunc (l)
call RemoveLocation (l)
set l = null
endfunction

It'd probably make leak-checking a whole lot easier (since the declaration and removal will be close to each other so you don't have to go back and forth between various functions)
 

Viikuna

No Marlo no game.
Reaction score
265
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top