• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

When does Editor create or remove gg (generated global variables)

Status
Not open for further replies.
About

gg= generated global
Here's a related tutorial explaining what a gg is: [Mini-Tutorial] Generated Globals

A gg is a global variable that is automatically created for prelaced objects that are used in triggers. Like preplaced units, doodads, cams, items, sounds, triggers, or regions.

In this thread I explain a short theory I have about when gg's are created, how they are kept in map, and when they are removed again.

The war3map.j file is created each time we save/built a map, so then is decided if to create or to remove gg's.

Shortly in before, I explain what is meant with "creating" or "removing" a gg variable for a map.
The gg variables are part of the globals block in the war3map.j file. So when we're speaking of "removing" a gg, it actually means Editor does simply not put it into the .j file, but it's not really removed from there. And "creating" does mean the gg var will be added to the .j file.

.wtg = GUI triggers
.wct = Custom Script / JASS triggers
.j = jass ( automatically generated output code, based on GUI triggers + JASS triggers)

When is a gg created?

When a GUI trigger references a preplaced object, this information is stord in the GUI .wtg file.
From here on, the gg will be created in the .j file. The gg can be used in JASS triggers, too.

But if you try directly to use a gg in JASS, without having a reference in .wtg / GUI file, it will throw a syntax error, saying this gg doesn't exist, as no gg is created on built.

When is a gg removed?

When you have a GUI trigger with a reference on a placed unit, let's say "gg_unit_Hpal_0001", and you remove the GUI trigger, it does following:
  1. Check if "gg_unit_Hpal_0001" is still referenced from anywhere else in the .wtg / GUI file
  2. Check if "gg_unit_Hpal_0001" is still referenced from anywhere else in the .wct / JASS file

  3. If it's not used anwehre else, the gg will not be created on map build.
  4. If it's still referenced from somewhere, it will keep this gg reference in the .wtg file. Even it's referenced only from .wct / JASS!
This means, if you have one GUI and one JASS trigger referencing a gg, and you decide to remove the GUI trigger, then it will still work fine. The gg will be created, and you can keep using it from JASS, even there's no GUI trigger actively using it.

Conclusion

So the design is not very good:
  • A reference in the .wtg / GUI trigger is required to create a gg.
  • Once having a reference in .wtg / GUI file, a reference from .wct / JASS code is enough, for keeping this reference in the .wtg, even when the GUI trigger is removed.
  • Referencing a gg alone from .wct / JASS code is not enogh, to create a gg.
Now comes the fun part. Even worse:

Situation:
  • Human Paladin 0001 exists on map ( would be "gg_unit_Hpal_0001" as a gg).
  • There's no .wtg / GUI reference, so no gg will be created.
Test:
  • Referencing gg_unit_Hpal_0001 directly from JASS alone will of course throw a syntax error, as explained before.
  • Also, even writing a JASS comment like "// gg_unit_Hpal_0001" will lead to a syntax error!!!
    The editor does not evaluate the trigger comment correctly, and thinks I'm trying to reference a gg that doesn't exist. Based on this assumption editor tries to use gg_unit_Hpal_0001 from then on in the .j file. Specifically, when preplaced units are created. But as no gg is created due to having no reference from .wtg / GUI, it will throw a syntax error.

    So the error does not occur at the "//gg_unit_Hpal_0001" part, because this is valid JASS comment, but it occurs in the code where the unit is created, that gg_unit_Hpal_0001 is used:
    set gg_unit_Hpal_0001 = CreateUnit( ... )
    ... instead of the normal way, if there's no gg used:
    set u = CreateUnit( ... ) // "u" is just a local variable
This means that a simple text search is made for "gg_" and it doesn't make a difference between comments and code, and the .j file will be built based on this reference assumption and leads to a syntax error.

On a side note, HiveWE does automatically create gg vars in the globals block, if required. A reference by JASS alone is enough, there's no reference in .wtg file needed.
 
Last edited:
Level 29
Joined
Jul 29, 2007
Messages
5,174
Would have been good to have this a long time ago, unfortunately I had to figure this stuff myself.
That being said, I am not sure in what context this is useful other than weird out-of-WE stuff :p

Nice job regardless.

One thing - you switched between wtg/wct when you first mention them.
 
Status
Not open for further replies.
Top