• 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.

[Solved] Globals / Constants Issue

Status
Not open for further replies.
Level 14
Joined
Oct 18, 2013
Messages
724
globals
constant unit G=gg_unit_hfoo_0000
endglobals

  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: call DisplayTextToForce( GetPlayersAll(), GetUnitName(G))
Display nothing on init. I don't see the issue. Since it displays nothing, I'm assuming G is null on Initialization. What workaround can I use? For a couple of my spells, theres a dummy unit that will cast stuff. I dont want to have to use the gg_unit_ name every time I need the dummy unit.
 
Level 14
Joined
Oct 18, 2013
Messages
724
I guess I should've mentioned that i already tried the wait 0.00 secs on init. Made no difference. Same result with 0.01 Time Elapsed. Kind of odd imo that it bugs this way.

So can you not set constant unit vars to units generated in World Edit?
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
Chaosy staph :alol:
Globals work everywhere, no matter where you place them ;)

The problem is that your G is initialized before your unit variable so it will be initialized to "null".
You have to make a trigger that runs on map init (or something like that) that will set G to that unit.
Then it will work. (Ofcourse then you dont have a constant.)
 
Level 14
Joined
Oct 18, 2013
Messages
724
The whole reason I wanted to use a constant is because the dummycaster unit was always the same unit, a constant. It would let me type less when ordering it to use abilities. Markin a Global Var. to it would just defeat the purpose of having constants in the first place.

Oh well.
 

Chaosy

Tutorial Reviewer
Level 41
Joined
Jun 9, 2011
Messages
13,241
Chaosy staph :alol:
Globals work everywhere, no matter where you place them ;)

Never said they didn't work everywhere. I just assumed the variable was compiled 'incorrectly' and put beneath the function/trigger he wants to use. Like trying to call a function which will get unexpected name error.
 
The problem is that your G is initialized before your unit variable so it will be initialized to "null".
exactly

do like this: (run at map init)
JASS:
function Trig_Declarations_Actions takes nothing returns nothing
globals
    real CenterX_A
    real CenterY_A    
endglobals

    set CenterX_A = GetUnitX(gg_unit_h01S_0136)
    set CenterY_A = GetUnitY(gg_unit_h01S_0136)
    
endfunction
//========================================
function InitTrig_Declarations takes nothing returns nothing
    set gg_trg_Declarations = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Declarations, function Trig_Declarations_Actions )
endfunction
 
Level 14
Joined
Oct 18, 2013
Messages
724
@ZiBitheWand3r3r , so I can just declare G but not set it to anything in the globals block? then set it so something? doesn't seem like this would be the case..
 
@ZiBitheWand3r3r , so I can just declare G but not set it to anything in the globals block? then set it so something? doesn't seem like this would be the case..

Yes. In your case, if you did this:
JASS:
globals
    unit G
endglobals

And then:
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set G = gg_unit_hfoo_0000
      • Custom script: call DisplayTextToForce( GetPlayersAll(), GetUnitName(G))
Then it would work assuming that gg_unit_hfoo_0000 is defined and appropriately assigned to the corresponding unit (gg variables are only defined once they are referenced through triggers!).
 
Level 14
Joined
Oct 18, 2013
Messages
724
Alright, so if I do "constant unit G" then I get "Cannot assign to constant G"

but if I do what you show "unit G" then its fine.

Good enough for me. Makes me question why constants are even allowed to be used for units. oh well. atleast I don't have to be typing udg_G or gg_unit_hfoo_0000, which is what I was looking for. Thanks P&F!
 
Status
Not open for further replies.
Top