| 01-01-2008, 10:36 PM | #1 |
Hi everyone and HAPPY NEW YEAR!! This is probably a dumb question, but I never cleared out these stuff: JASS:local integer i1 = 100 local integer i2 = i1 set i1 = 0 This means that i2 will become 0 too, right? JASS:local group g1 = CreateGroup() local group g2 = g1 call DestroyGroup(g1) This means that g2 will also be destroyed, right? JASS:local unit u1 = CreateUnit(...) local unit u2 = u1 set u1 = null This means that u2 will also become null, right? But what about: JASS:local real x = 10 local real y = 20 local real sum = x + y set x = 5 Doesn't this change the sum variable also? Since x changed, doesn't then sum become 25? JASS:local real x = 10 local real sum = x + x // or 2 * x set x = 5 Doesn't this change the sum variable from 20 to 10? I'm a bit confused guys..... |
| 01-01-2008, 10:42 PM | #2 |
try it and let it give out by a debugMSG^^ |
| 01-01-2008, 10:44 PM | #3 |
Answers in order: No Yes No No No This is because integers, reals and strings do not extend handles. Units, groups, locations, items, all extend handles. A variable does not store a new handle, but only points to the given handle. If you have 2 variables set to the same unit, you don't have 2 units, you have 1 unit with 2 different references. Destroying the unit with either of the references will cause the unit to be destroyed. All references will still point to the unit, but it will be destroyed. Integers, reals and strings are different. When you set a new integer, you create a new variable. If you then set another new variable based on the old one, you have created a new variable. Each variable is independent to the others. |
| 01-01-2008, 10:46 PM | #4 |
What you said about destroying groups is true and applies to all handles. Nothing else you speculated is true, especially with primitives (integer, real, string, boolean). When you did this: JASS:local unit u1 = CreateUnit(...) local unit u2 = u1 set u1 = null JASS:local unit u1 = CreateUnit(...) local unit u2 = u1 call KillUnit(u1) |
| 01-01-2008, 10:59 PM | #5 |
so you could manage var transfer when you convert it before in a integer? ^^ example a unit to a integer, save it, and then the integer to a unit... i think that would be possible, or? |
| 01-01-2008, 11:21 PM | #6 |
No, because the integer retrieved from H2I is still a pointer to the handle. Converting it back to a unit variable is still only a pointer. |
| 01-02-2008, 12:19 AM | #7 |
when u set a var in jass equal another, it doesnt mean ure pointing or making a reference to that var. it just copy the value into the new var. But for handler its different. u can see this with a unit, the unit wont be copied in game when u set another variable = this unit. So logically the variables for units only point to the unit. therefore if the unit is destroyed, the unit for all the vars pointing to it will too (ofc). But these vars isnt nulled, they will then be pointing to somewhere which contains nothing. therefore u must set var=null to free this place/slot in the memory. so wc3 can use it. |
| 01-02-2008, 01:17 AM | #8 |
war3 is fully handle based. strings integers and reals are also handles. i.e. don't copy the values. |
| 01-02-2008, 12:48 PM | #9 |
Wow, so much replies..... Thanks, all of you, now I get it :) |
