1. Choose the best Old Gods themed skin at the Texturing Contest #29 - Poll!
    Dismiss Notice
  2. Melee Mapping Contest #2 - Poll is up! Vote for the best competitive 1v1 map!
    Dismiss Notice
  3. Please help test custom maps and more on the latest PTR!
    Dismiss Notice
  4. Evolution complete! Make Darwin proud and go vote in the Techtree Contest #12 - Poll.
    Dismiss Notice
  5. Icon Contest #17 - Results are out! Step by to congratulate our winners!
    Dismiss Notice
  6. We've created the Staff Job Openings thread. We're currently in need of icon, video production, and social/multimedia positions to be filled. Thank you!
    Dismiss Notice

[Mini-Tutorial] Generated Globals

Discussion in 'General Mapping Tutorials' started by PurgeandFire, Nov 19, 2007.

  1. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,381
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Introduction:

    Generated Globals are globals that are generated variables for a certain handle. A handle is any variable other than a string, boolean, code, integer, or real. If you open the common.j, the index of Warcraft natives (either extract it from the MPQ or get some JASS program such as JASSCraft that includes it), you will notice all the variables listed will extend handle, or extend a different variable which extends a handle. The five variables I mentioned, though, aren't handles because they don't extend handle, and they can't be directly created.

    So, it generates a global for any variable type other than strings, boolean, code, integers, and reals.

    Purpose of this Tutorial:

    Though generated globals are only used in certain functions, they are still important and it is good to know a bit about them. So after you read this tutorial, you shouldn't just go and generate globals because:

    1 - In GUI, you can't even create or access generated globals unless you are using them for a particular function.
    2 - In JASS, you have trusty NewGen globals.

    What are Generated Globals?

    Generated globals are globals that WE creates for certain handles in your map. Take this for instance:
    • Trigger
      • Events
        • Unit - Footman 0001 <gen> is attacked


    In this simple trigger, you have one <gen>. This actually means that it is a generated global.

    <gen> = Generated Globals

    As you can see, Footman 0001 is the generated global. Obviously, this is a preplaced unit on your map which the WE calls "Footman 0001".

    If you convert this trigger to JASS by going to Edit | Convert to Custom Text, it will be something like this in the initialization function (Init_Trig_Trigger):
    Code (vJASS):

        call TriggerRegisterUnitEvent( gg_trg_Trigger,gg_unit_####_0001,EVENT_UNIT_ATTACKED)
    // #### symbolizes the rawcode of the unit, or in this case, footman 0001
     
    //blank line
     
     


    This is probably really confusing for you, so let me break it down.
    • call = Tells that it is about to "call" or start a function
    • TriggerRegisterUnitEvent = This is the function to be called. It registers a unit event.
    • gg_trg_Trigger = This is a generated global for the current trigger you are in.
    • gg_unit_####_0001 = This is the generated global for the unit that is being attacked, in this case, footman_001.
    • EVENT_UNIT_ATTACKED = This is the type of event for the trigger.
    In this, you'll notice two generated globals. Yes, the current trigger is actually a generated global as well. So, every trigger is a generated global.

    Generated globals, in JASS, always follow this standard:
    - gg_TYPE_NAME

    gg = Generated Global
    TYPE = Type of variable to be generated
    NAME = This is the name of the variable, but in some cases for widgets (units, destructables, and items) it is the rawcode then the number of it on the map.

    When you use a generated global, it must always have the prefix gg_TYPE plus the name. This is similar to globals which require "udg_" as a prefix.

    Now that you basically understand the rules and what generated globals are, you can know walk out there with a clear knowledge of it.

    Summary:

    Generated globals, to sum it all up, are just initiated handles in your map that are generated in WE to represent a certain handle such as a trigger or a widget. In fact, most of the times, generated globals are only used for triggers, widgets, regions, and cameras because others aren't visible in your map.

    Now that you know this information, you can now know what those confusing <gens> mean.
     
    Last edited: Mar 2, 2011
  2. 1)ark_NiTe

    1)ark_NiTe

    Joined:
    Nov 1, 2006
    Messages:
    1,672
    Resources:
    5
    Maps:
    1
    Spells:
    3
    Tutorials:
    1
    Resources:
    5
    This is great, but it would be a lot better if you prefaced it with a definition of a handle. I have no clue what one is!
     
  3. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,381
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Thanks, I'll add the definition of a handle.

    Also, does anyone know the rawcode of a footman? I think it was 'ahal' or something similar.
     
  4. 1)ark_NiTe

    1)ark_NiTe

    Joined:
    Nov 1, 2006
    Messages:
    1,672
    Resources:
    5
    Maps:
    1
    Spells:
    3
    Tutorials:
    1
    Resources:
    5
    That is just obsolete information. Don't worry about putting it there, it could confuse people thinking that all unit rawcodes will be that of the footman. Keep it as is in my opinion.
     
  5. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,164
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Rawcode of a footman is 'hfoo'. Oh, and unit IDs have 4 digits, not 3. (Eg Footman 0001 aka gg_unit_hfoo_0001)
     
  6. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,381
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Ok, and I restated my comment so that it fits it more generally.

    Fixed.
     
  7. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,381
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Bump..

    So.. I guess if this isn't approved yet, but doesn't have any comments against/with it, then it is ignored? :p

    Needs meh feedback and whether or not it'll be approved.
     
  8. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,164
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    It's hard to tell where this goes... Miscellaneous Tutorials? General Mapping TUtorials? Bleh.
     
  9. busterkomo

    busterkomo

    Joined:
    Jun 17, 2007
    Messages:
    1,419
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Miscellaneous I would think, since both JASS and General don't really have a place for it.
    Anyways, Nice tut, +Rep ;)
     
  10. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,381
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Miscellaneous is mainly for external stuff. I think General mapping would be the best since this is both gui and JASS. I dunno though..
     
  11. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,164
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    To general it is!