• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Set Globals after Units are Generated?

Status
Not open for further replies.
Level 18
Joined
Jan 21, 2006
Messages
2,552
Or you could use a unit-group to pick every unit that exists at map initialization (preplaced units will be included). From there you would just add each of them to a global array, as you mentioned.
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
So there's no way to set say:

global
GUI_PickRanger = gg_unit_n000_0001
endglobals

if gg_unit_n000_0001 is placed on the map via worldedit. (And is therefore created AFTER global delcaration) Try it, it will tell you the unit doesn't exist.

To make life easier the preplaced GUI button units are all set to a global, GUI_XXXX, so the global can be referenced during coding instead of gg_unit_xxxx_xxxx.

There's a lot so it really makes the code long and large.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
if gg_unit_n000_0001 is placed on the map via worldedit. (And is therefore created AFTER global delcaration) Try it, it will tell you the unit doesn't exist.

If you use a GUI trigger to reference the specific unit, convert to custom text, and use the value shown there you won't get those errors saying that the unit doesn't exist.
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
gg_unit_n000_0001 is the same unit as the one when you set variable = value and convert to custom text.

My current work-around which doesn't work and causes bugs in map initialization:

JASS:
globals
    //Conversions for MENU BOX items 
    unit GUI_Units
    unit GUI_U_Create
    unit GUI_U_Kill
    unit GUI_U_Remove
    unit GUI_U_Side
    unit GUI_U_Move
    unit GUI_U_Give
    unit GUI_U_Size
    unit GUI_U_Revive
    unit GUI_U_Tint
    unit GUI_U_Tint_Invis
    unit GUI_U_Tint_White
    unit GUI_U_Tint_Yellow
    unit GUI_U_Tint_Green
    unit GUI_U_Tint_Red
    unit GUI_U_Tint_Blue
    unit GUI_U_Invincible


//Items
    unit GUI_Items
    unit GUI_I_Create
    unit GUI_I_Remove
    unit GUI_I_Move
    unit GUI_I_P_GoldPile
    unit GUI_I_P_GoldCoin
    unit GUI_I_P_PileOfRiches


//Doodads
    unit GUI_Doodads
    unit GUI_D_Create
    unit GUI_D_Remove
    unit GUI_D_Kill
    unit GUI_D_Revive
    unit GUI_D_Toggle

    unit GUI_D_P_Grove
    unit GUI_D_P_Junk
    unit GUI_D_P_Crates
    unit GUI_D_P_Rocks
    unit GUI_D_P_Tree
    unit GUI_D_P_Blight
    unit GUI_D_P_Dispel
    unit GUI_D_P_WoodenBridge
    unit GUI_D_P_StoneBridge
    unit GUI_D_P_Gate
    unit GUI_D_P_ElvenGate
    unit GUI_D_P_DemonicGate
    unit GUI_D_P_Line1 
    unit GUI_D_P_Line2 
    unit GUI_D_P_StoneWall 
    unit GUI_D_P_FenceLine 
    
//Misc
    unit GUI_Misc 
    unit GUI_M_Portal 
    unit GUI_M_Cinematic 
    unit GUI_M_Boot 


//Toolbox
    unit GUI_Toolbox
    unit GUI_T_Tile_Blue
    unit GUI_T_Tile_Teal
    unit GUI_T_Tile_Purple
    unit GUI_T_Tile_Orange
    unit GUI_T_Tile_Green
    unit GUI_T_Tile_Pink
    unit GUI_T_Tile_Brown

    unit GUI_T_Tile_Enemy
    unit GUI_T_Tile_Ally

    unit GUI_T_Tile_Gray
    unit GUI_T_Tile_Cyan
    unit GUI_T_Tile_DarkGreen
endglobals

function SetGlobals takes nothing returns nothing

        //Conversions for MENU BOX items 
    set GUI_Units = gg_unit_n000_0001
    set GUI_U_Create = gg_unit_n000_0002
    set GUI_U_Kill = gg_unit_n000_0003
    set GUI_U_Remove = gg_unit_n000_0004
    set GUI_U_Side = gg_unit_n000_0005
    set GUI_U_Move = gg_unit_n000_0006
    set GUI_U_Give = gg_unit_n000_0007
    set GUI_U_Size = gg_unit_n000_0009
    set GUI_U_Revive = gg_unit_n000_0010
    set GUI_U_Tint = gg_unit_n000_0011
    set GUI_U_Tint_Invis = gg_unit_n000_0016
    set GUI_U_Tint_White = gg_unit_n000_0017
    set GUI_U_Tint_Yellow = gg_unit_n000_0018
    set GUI_U_Tint_Green = gg_unit_n000_0021
    set GUI_U_Tint_Red = gg_unit_n000_0020
    set GUI_U_Tint_Blue = gg_unit_n000_0019
    set GUI_U_Invincible = gg_unit_n000_0012


//Items
    set GUI_Items = gg_unit_n000_0033
    set GUI_I_Create = gg_unit_n000_0034
    set GUI_I_Remove = gg_unit_n000_0035
    set GUI_I_Move = gg_unit_n000_0036
    set GUI_I_P_GoldPile = gg_unit_n000_0132
    set GUI_I_P_GoldCoin = gg_unit_n000_0133
    set GUI_I_P_PileOfRiches = gg_unit_n000_0079


//Doodads
    set GUI_Doodads = gg_unit_n000_0037
    set GUI_D_Create = gg_unit_n000_0038
    set GUI_D_Remove = gg_unit_n000_0039
    set GUI_D_Kill = gg_unit_n000_0040
    set GUI_D_Revive = gg_unit_n000_0041
    set GUI_D_Toggle = gg_unit_n000_0042

    set GUI_D_P_Grove = gg_unit_n000_0123
    set GUI_D_P_Junk = gg_unit_n000_0068
    set GUI_D_P_Crates = gg_unit_n000_0096
    set GUI_D_P_Rocks = gg_unit_n000_0154
    set GUI_D_P_Tree = gg_unit_n000_0124
    set GUI_D_P_Blight = gg_unit_n000_0125
    set GUI_D_P_Dispel = gg_unit_n000_0131
    set GUI_D_P_WoodenBridge = gg_unit_n008_0127
    set GUI_D_P_StoneBridge = gg_unit_n009_0128
    set GUI_D_P_Gate = gg_unit_n00G_0136
    set GUI_D_P_ElvenGate = gg_unit_n00H_0137
    set GUI_D_P_DemonicGate = gg_unit_n00F_0138
    set GUI_D_P_Line1 = gg_unit_n00P_0183
    set GUI_D_P_Line2 = gg_unit_n00P_0182
    set GUI_D_P_StoneWall = gg_unit_n00O_0164
    set GUI_D_P_FenceLine = gg_unit_n000_0152

//Misc
    set GUI_Misc = gg_unit_n000_0043
    set GUI_M_Portal = gg_unit_n000_0044
    set GUI_M_Cinematic = gg_unit_n000_0045
    set GUI_M_Boot = gg_unit_n000_0047


//Toolbox
    set GUI_Toolbox = gg_unit_n000_0048
    set GUI_T_Tile_Blue = gg_unit_n000_0049
    set GUI_T_Tile_Teal = gg_unit_n000_0050
    set GUI_T_Tile_Purple = gg_unit_n000_0051
    set GUI_T_Tile_Orange = gg_unit_n000_0052
    set GUI_T_Tile_Green = gg_unit_n000_0053
    set GUI_T_Tile_Pink = gg_unit_n000_0054
    set GUI_T_Tile_Brown = gg_unit_n000_0055

    set GUI_T_Tile_Enemy = gg_unit_n000_0056
    set GUI_T_Tile_Ally = gg_unit_n000_0057

    set GUI_T_Tile_Gray = gg_unit_n000_0104
    set GUI_T_Tile_Cyan = gg_unit_n000_0179
    set GUI_T_Tile_DarkGreen = gg_unit_n000_0207
    
endfunction


function InitTrig_SetGlobals takes nothing returns nothing
 local trigger t = CreateTrigger()
    call TriggerAddAction(t, function SetGlobals)
 set t = null
endfunction


This is what I'd like to do:

JASS:
globals
    constant unit GUI_U_Invincible = gg_unit_n000_0012
endglobals

But obviously it won't work.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
In the callback function for a 0-second timer running at map initialization, do all your global variable setup. By that point (the thread after initialization) the values of gg_unit_H601_0010 generated constants will be allocated and you should be able to reference them properly. If you have a local variable and you set it to one of those generated names then you will see that works, it all depends on the placement of your code.
 
Status
Not open for further replies.
Top