| 03-12-2007, 11:29 PM | #1 |
Hi, I have just a very fast question! If I have a trigger like this: JASS:local player p = null local integer index = 1 loop set p = GetOwningPlayer( udg_Unit[ index ] ) call DoSomething( ... ) endloop set p = null When I give a new value to the variable p, do I have to nullify it before using the new value or nullifying it at the end is enough? Do I have to write the following? JASS:local player p = null local integer index = 1 loop set p = GetOwningPlayer( udg_Unit[ index ] ) call DoSomething( ... ) set p = null endloop set p = null Thanks! |
| 03-12-2007, 11:32 PM | #2 |
http://wc3campaigns.net/showthread.php?t=81872 The tutorial link in my sig and the main page is not jsut for show ;) |
| 03-12-2007, 11:34 PM | #3 |
The first block of code is correct, you only have to nullify it once at the end. |
| 03-13-2007, 12:11 PM | #4 | |
Quote:
Thank you both! |
| 03-13-2007, 01:27 PM | #5 |
You don't need to null player variables. |
| 03-13-2007, 01:39 PM | #6 | ||
Quote:
Quote:
Try to read more thoroughly next time ;) |
| 03-13-2007, 02:37 PM | #7 |
player is constant function player(0) == player(0) its like boolexpr and some other types, same arguments cause same return value. to check need value to be nulled or not compare it to it self location(0,0) != location(0,0) soo this type have to be removed\nulled |
| 03-13-2007, 06:10 PM | #8 |
Thank you all guys, actually I read all the articles/posts and I was trying to set up my mind with some basic "rules": 1) "One time" local handles variables should be nullified (so heroes/players does not, right?); 2) Changing the value of a variable = nullifing it (but you need to nullify it at the end if it is local, right?); 2) Global variables don't need to be nullified; 2) If a handle is used during a function call, for example JASS:call Function( GetTriggerUnit( ) ) then the GetTriggerUnit doesn't need to be nullified using a new local variable since it doesn't leak, right? Are those sentences wrong? What about this: JASS:local location loc = null local integer i = 0 loop exitwhen i > 100 set loc = Location( AnyX, AnyY ) // do something with the new created location // ... call RemoveLocation( loc ) set i = i + 1 endloop set loc = null Does it leak? Thanks!!! |
| 03-13-2007, 07:17 PM | #9 |
Sounds right and no, that won't leak. |
