| 06-26-2008, 07:40 AM | #1 |
So anyone who has used GUI probably knows about that weird, random trick you can do to make globals act like locals in GUI. For those of you don't, here's what it looks like: Trigger: Anyway, what I'm wondering is this: why does it work? Do we have any clue what this does to the parser to make it work, because it seems like if it was compiled normally it simply wouldn't compile and it would look like: JASS:function Trig_MyTrigger_Actions takes nothing returns nothing local unit udg_MyUnit set udg_MyUnit = GetTriggerUnit() call PolledWait(2.00) call KillUnit(udg_MyUnit) set udg_MyUnit = null endfunction |
| 06-26-2008, 07:47 AM | #2 |
It works because by using the script "Local unit udg_MyUnit" you're defining the variable udg_MyUnit as a local unit variable. However, that definition doesn't occur until the game runs, so the variable appears to be global. |
| 06-26-2008, 07:51 AM | #3 |
Okay, that makes sense... but why doesn't it generate a syntax error? |
| 06-26-2008, 07:56 AM | #4 |
Just a bug with the syntax error. Something to do with the way it handles scope, presumably. As an interesting side note, doing that with an array does cause a syntax error. |
| 06-26-2008, 08:29 AM | #5 |
There are 2 udg_MyUnit variables, one local and one global. It compiles somewhat like this: JASS:globals unit udg_MyUnit endglobals function Trig_MyTrigger_Actions takes nothing returns nothing local unit udg_MyUnit set udg_MyUnit = GetTriggerUnit() call PolledWait(2.00) call KillUnit(udg_MyUnit) set udg_MyUnit = null endfunction and since local variables take precedence over globals ones global variable is never used inside Actions (but still exists) In fact if you would to remove the local unit udg_MyUnit from the beginning of action the action would be using global variable (no-mui) |
| 06-26-2008, 08:48 AM | #6 |
JASS == voodoo |
| 06-28-2008, 05:32 PM | #7 |
Y'know, I always confuse Pyrogasm and Phoenix-IV. |
| 06-28-2008, 08:59 PM | #8 |
Well then, if it's such a simple syntax thing... why doesn't it work for more than one variable per function...? |
| 06-28-2008, 09:18 PM | #9 |
Voodoo. Blizzard's defensive programming is awful. It's probably a bug in their compiler that it works at all. |
| 06-29-2008, 07:30 AM | #10 | |
Quote:
Make a simple test map, compile it, go to logs/inputwar3map.j and tell us. |
| 06-29-2008, 08:11 AM | #11 |
I'm going to go with Griffen's explanation. It's Voodoo, a Wizard probably did it, or at least was responsible for it. |
| 06-29-2008, 09:11 AM | #12 |
Wizards dont do voodoo. |
| 06-29-2008, 11:40 AM | #13 |
not voodoo, just bad programming :P |
| 06-29-2008, 02:13 PM | #14 | |
Quote:
BLizz were intending GUI people to do global shadowing like this, they even hacked the compiler so it becomes non-case-sensitive after you do that, so GUI guys don't have to bother with correct capitalization... |
| 06-30-2008, 08:24 AM | #15 | |
Quote:
If they were so good to GUI guys why they did not add Remove functions to GUI. |
