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

Undeclared variable

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I'm trying to use these variables in my code but it states that they are undeclared, no idea why this is the case:

Compile errors:
JASS:
//***************************************************************************
//*
//*  Unit Creation
//*
//***************************************************************************

//===========================================================================
function CreateBuildingsForPlayer0 takes nothing returns nothing
    local player p= Player(0)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set gg_unit_hbar_0000=CreateUnit(p, 'hbar', - 12832.0, 2464.0, 270.000)
    set gg_unit_hbar_0001=CreateUnit(p, 'hbar', - 14560.0, 2528.0, 270.000)
    set gg_unit_hbar_0002=CreateUnit(p, 'hbar', - 14816.0, 1632.0, 270.000)
endfunction

I don't know what more to say that I'm using the variable gg_unit_hbar_0000 in another scope and if I disable the usage, this error does not appear.
 
generated globals, so gg_ variables are created automatically, but only if needed. "Needed" means in terms of that they're being used.

gg_ variables' purpose is to access pre-placed handles on the map, like those barracks in your code. Unfortunately:
  • JASS on itself lacks of accessing pre-placed handles, like gg_unit ..
  • no gg_ variables exist by default which otherwise could mean a huge variables overhead, that are potentially never used
So what GUI does is, when you take usage of for example a pre-placed barracks inside a trigger, then such a gg_ variable is automatically created. But if there are no references from GUI towards the pre-placed unit, then the variable won't exist, and trying to access it will also throw the "undeclared variable" error, when trying to access it only via JASS.

This topic with accessing pre-placed handles is one advantage from GUI.
 
Status
Not open for further replies.
Top