| 07-21-2007, 10:29 PM | #1 |
Do unit (not unit type) variables leak? If so, can somebody tell me how to um... unleak them? I've searched everywhere, but where it says unit... it basically is just "create unit on point" instead of how to fix unit leaks. |
| 07-21-2007, 11:14 PM | #2 |
ANY variable is not leaking... wait a bit so you get it explained. ^^ |
| 07-21-2007, 11:19 PM | #3 |
What Toadcop means is, there are methods for handling all variables carefully enough that they should not leak... except for trackables. There is a RemoveUnit function and if you assign a unit to a local variable, you must assign null to that variable after removing the unit. |
| 07-21-2007, 11:27 PM | #4 |
Trigger: Set TempUnit = (Target unit of ability being cast)Does that leak? If so, how can I clean it... I'm having a blond day, more blond than usual... |
| 07-21-2007, 11:30 PM | #5 |
If you use that global more than once, it won't leak. Things only leak if you set a variable's value to something, use the variable once, and never use that variable again and forgetting to clean it. Globals often don't leak, but locals do. |
| 07-21-2007, 11:32 PM | #6 |
Making a (local) unit variable, if it's not a unit to be removed (like a hero), just null the variable. otherwise, if it's a dummy unit for example, use RemoveUnit((your unit variable)), and null it. |
| 07-22-2007, 12:02 AM | #7 |
if you create something (CreateUnit()) you must destroy it (RemoveUnit()). JASS also is broken in the sense that destroying something will not work if it is still in use. (if a variable is still pointing to it) locals do not stop pointing at something implicitly at the end of a function. globals would also suffer from this, but who cares, as their value will eventually be changed, destroying the remaining reference to the object in question. to understand this well, first you must understand handles. which im too lazy to explain this second. |
| 07-22-2007, 12:31 AM | #8 |
One last question... nobody ever told me this but what's the difference between locals and globals? |
| 07-22-2007, 12:53 AM | #9 | |
Quote:
Units remove themselves after decaying, so killing is equally okay for a unit to not leak. Globals are variables that are just that... Global. They can be used in any function anywhere. Locals are specific to the function in which they are declared (Unless moved to other functions via globals or some other method). |
| 07-22-2007, 12:54 AM | #10 |
So... Globals are the variables made in the Variable Editor, and locals aren't the variables made in the Variable Editor? |
| 07-22-2007, 12:56 AM | #11 | |
Quote:
|
| 07-22-2007, 01:03 AM | #12 |
JASS:globals integer a endglobals function foo takes nothing returns nothing local integer b set a = 3 set b = 4 endfunction function bar takes nothing returns nothing set a = 5 set b = 6 call foo() call BJDebugMsg(I2S(a)+I2S(b)) endfunction JASS:function foo takes nothing returns nothing local integer b = GetRandomInt(1, 100) call TriggerSleepAction(5.0) call BJDebugMsg(I2S(b)) endfunction function bar takes nothing returns nothing call ExecuteFunc("foo") call TriggerSleepAction(1.0) call ExecuteFunc("foo") call TriggerSleepAction(1.0) call ExecuteFunc("foo") endfunction I hope this illustrates the difference between locals and globals well enough. |
| 07-22-2007, 01:11 AM | #13 |
lets introduce you to the concept of scope. in jass, there are 2 scores for variables, 1 for functions. things only exist in the scope they are created in, and "child" scopes of that. for example: JASS:globals integer i = 5 endglobals function abc takes nothing returns nothing local integer k = i endfunction function def takes nothing returns integer return i endfunction the variable "i" (a global) exists in all functions. the variable "k" (a local) exists only in the function "abc". paramiters (what a function "takes") are esentally locals. functions exist in one scope, the global scope. you can't do JASS:function abc takes nothing returns integer function def takes nothing returns integer return 4 endfunction return def() endfunction |
| 07-22-2007, 04:06 AM | #14 |
I see... thanks for the clarification, +Rep to all those who put time into helping. |
