| 05-23-2007, 02:37 PM | #1 |
Do you have to nullify parameter objects? Like JASS:function ok takes unit u returns nothing ... set u = null //like this? endfunction |
| 05-23-2007, 02:43 PM | #2 |
Nope, parameters are automaticly cleaned after use. |
| 05-23-2007, 07:11 PM | #3 |
I would like to ask a question here, but I don't want to start a new topic: Is it true that returned values leak, because you can't nullify them? Example: function blabla takes nothing returns unit local unit u = ...... ...... return u endfunction If it leaks, how can you fix it? |
| 05-23-2007, 07:26 PM | #4 |
I use I2H, but people here might be screaming at me by now (hugs my pillow). like JASS:function H2I takes handle h returns integer return h return 0 endfunction function I2U takes integer i returns unit return i return null endfunction function blabla takes nothing returns unit local unit u = ... local integer u_int = H2I(u) ... set u = null return (I2U(u_int)) endfunction |
| 05-23-2007, 07:38 PM | #5 |
I've been wondering about that for ages, but I don't think it will be leaking. Maybe somebody go test it out, if it does... image the codes that I'll be redoing... |
| 05-23-2007, 07:43 PM | #6 |
H2I = good I2U = bad. regarding this JASS:globals unit returnaux_unit endglobals function IwantAunit takes nothing returns unit local unit u = CreateUnitStuff() call UnitAddAbility(u,'Aloc') set returnaux_aunit = u set u=null return returnaux_aunit endfunction |
| 05-23-2007, 08:23 PM | #7 |
And this is multi-instanceable for sure? Like, is it possible for the global to be overwritten without TriggerSleepAction? |
| 05-23-2007, 08:36 PM | #8 |
No it's not, not even with any type of waits, since it's used and returned right away, so there's no way you can overwrite it. |
| 05-23-2007, 08:41 PM | #9 |
It would be possible if another trigger could run between the set returnaux_aunit = u and return returnaux_aunit, this can only happen if there's, as you say, a TriggerSleepAction call used, or if a function is called that triggers another event, for example a "kill unit" call would cause a trigger with an event "a unit dies" to interrupt the execution of the thread from where the unit was killed, anyway, as you can see nothing of that sort is there in Vexorian's example. |
| 05-23-2007, 09:12 PM | #10 |
You can use function wrappers instead of a global, not that there is a problem with using globals; JASS:function SomeFunc takes unit u returns unit // Do stuff with u.. return u endfuction function GetAUnit takes nothing returns unit return SomeFunc(CreateUnit(...)) endfunction |
| 05-23-2007, 10:20 PM | #11 |
JASS:globals unit returnaux_unit endglobals function IwantAunit takes nothing returns unit set returnaux_aunit = CreateUnitStuff() call UnitAddAbility(returnaux_aunit,'Aloc') return returnaux_aunit endfunction |
| 05-24-2007, 03:31 AM | #12 |
so... avoid using locals will be a better idea when returning stuffs ? |
| 05-24-2007, 03:49 AM | #13 |
how strange that the communities view on global usage change so much recently. |
| 05-24-2007, 02:45 PM | #14 |
weaaddar i have used A LOT global vars more than 1 year ago ^^ (i have create a custom common.j and have imported it in map) so it's nothing new... |
| 05-24-2007, 03:25 PM | #15 |
-.- I was told that global vars are slower than locals so I was trying to avoid use global vars... guess I was wrong... oh shit... |
