• 🏆 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!

[AI] [solved] Setting Global Variables

Status
Not open for further replies.
Level 18
Joined
Mar 16, 2008
Messages
721
I'm trying to set global variables in an AI script so I don't need to use those cryptic unit IDs however when I add this piece of code to the script the script apparently doesn't run.

Can anyone educate me on what is wrong here? Thank you.

JASS:
//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************
                     
globals
/// integer                 tier                       = 0
    integer                 attackWave                 = 0
    integer                 nextDelay                  = 0
    integer                 awGold                     = 0
    integer                 awWood                     = 0
    /// King Heroes
    constant integer        SOVEREIGN                  = 'H01L'
    constant integer        MONARCH                    = 'HC18'
    constant integer        MAJESTY                    = 'H03I'
    /// Prince Heroes
/// constant integer        PALADIN                    = 'Hpal'
    constant integer        MAGE                       = 'H01G'
    constant integer        WARRIOR                    = 'H03J'
    /// King Hero Abilities
    constant integer        ROYAL_BANISH               = 'A006'
    constant integer        KING_AURA                  = 'A00K'
    constant integer        KING_COURT                 = 'A00C'
/// constant integer        THUNDER_CLAP               = 'AHtc' /// Sovereign only / "Royal Revenge"
    constant integer        ROYAL_SHOCKWAVE            = 'A06G' /// Monarch only
    constant integer        ROYAL_BLIZZARD             = 'A06H' /// Majesty only
    constant integer        ROYAL_SUMMON               = 'A01H' /// based on blizzard spell so ais tend to use improperly
    /// Prince Hero Abilities
/// constant integer        HOLY_BOLT                  = 'AHhb' /// Holy Light / "Royal Blessing"     
/// constant integer        BLINK                      = 'AEbl' /// Royal Mage only
/// constant integer        DIVINE_SHIELD              = 'AHds' /// Royal Pally only
/// constant integer        DEVOTION_AURA              = 'AHad'
    constant integer        MASS_REZ                   = 'A06E' /// Royal Pally only
/// constant integer        MASS_TELEPORT              = 'AHmt' /// Royal Mage only
    constant integer        ATTRIBUTE_BONUS            = 'Aamk'
    constant integer        FERAL_IMPACT               = 'A01U' /// Royal Warrior only
    constant integer        CRIT_STRIKE                = 'A06K' /// Royal Warrior only
    constant integer        AVATAR                     = 'A06I' /// Royal Warrior only
    constant integer        BLADESTORM                 = 'A06J' /// Royal Warrior only
    /// Buildings               
/// constant integer        CASTLE                     = 'hcas'
/// constant integer        TOWN_HALL                  = 'htow'
/// constant integer        LUMBER_MILL                = 'hlum' /// already set in J file, will this be a problem?
/// constant integer        BLACKSMITH                 = 'hbla'
    constant integer        ROYAL_BARRACKS             = 'H02P'
    constant integer        FARM_1                     = 'h003'
    constant integer        FARM_2                     = 'h005'
    constant integer        FARM_3                     = 'h006'
    constant integer        FARM_4                     = 'h007'
    constant integer        FARM_5                     = 'h00S'
/// constant integer        BARRACKS                   = 'hbar' /// "Stables" (tier 1) defined as Barracks in .j file
    constant integer        STABLES_2                  = 'h00A'
    constant integer        STABLES_3                  = 'h00B'
    constant integer        STABLES_4                  = 'h00K'
    constant integer        GARRISON_1                 = 'h00F'
    constant integer        GARRISON_2                 = 'h00G'
    constant integer        GARRISON_3                 = 'h00H'
    constant integer        ROYAL_FACTORY              = 'h01F'
    constant integer        RESEARCH_CENTER_1          = 'h01H'
    constant integer        RESEARCH_CENTER_2          = 'h02Q'
    constant integer        FOUNTAIN                   = 'n020'
    constant integer        ROYAL_SHIPYARD             = 'h01S'
    constant integer        STONEMASON_TOWER           = 'h02Y'
    constant integer        ROYAL_WORKSHOP             = 'h02Z'
    constant integer        FARM_COTTAGE               = 'h034'
/// constant integer        SANCTUM                    = 'hars' /// "Tower of Wizardry"
    constant integer        TOWER_WIZARDRY_2_BUILT     = 'h031'
    constant integer        TOWER_WIZARDRY_2_UPGRADE   = 'h03H'
    constant integer        ROYAL_CHURCH               = 'h01A'
/// constant integer        ARCANE_VAULT               = 'hvlt' /// "Royal Market" (tier 1)
    constant integer        ROYAL_MARKET_2             = 'h01K'
    constant integer        TOWER_BASIC                = 'h03X'
/// constant integer        GUARD_TOWER                = 'hgtw' /// "Guard Tower" (tier 1)
    constant integer        GUARD_TOWER_2              = 'h00Q'
    constant integer        GUARD_TOWER_3              = 'h00P'
/// constant integer        CANNON_TOWER               = 'hctw' /// "Cannon Tower" (tier 1)
    constant integer        CANNON_TOWER_2             = 'h033'
/// constant integer        ARCANE_TOWER               = 'hatw' /// "Arcane Tower" (tier 1)
    constant integer        ARCANE_TOWER_2             = 'h018'  
    constant integer        ARCANE_TOWER_3             = 'h02V'    
    constant integer        TOWER_COLD_1               = 'ndt1'
    constant integer        TOWER_COLD_2               = 'ndt2'
    constant integer        TOWER_COLD_3               = 'n01H'
    constant integer        TOWER_COLD_4               = 'n01I'
    constant integer        TOWER_FLAME_1              = 'nft1'
    constant integer        TOWER_FLAME_2              = 'nft2'
    constant integer        TOWER_FLAME_3              = 'n029'
    constant integer        TOWER_FLAME_4              = 'n02A'
    constant integer        TOWER_FLAME_5              = 'n02B'
    constant integer        TOWER_FLAME_6              = 'n02C'
    constant integer        TOWER_ROYAL_1              = 'hC17'
    constant integer        TOWER_ROYAL_2              = 'h000'
    constant integer        TOWER_ROYAL_3              = 'h001'
    constant integer        TOWER_ROYAL_4              = 'h00C'
    constant integer        TOWER_ROYAL_SKY            = 'n00D'
 
endglobals
 
Last edited:
Level 18
Joined
Mar 16, 2008
Messages
721
omg how did i do that twice! Well I removed that and along your line of thinking also removed duplicates that are also defined in the common.ai file. Unfortunately when I test the script, it seems to do nothing. On the other hand, when I tested right before adding this section, it was running.
I updated globals section in the original post if you can imagine any other possible errors.
 
Last edited:
Level 18
Joined
Mar 16, 2008
Messages
721
Very grateful for your attention!

I’m fairly sure the global declarations are the problem. Because before I added this section, the code was running.

Edit: should i put debug messages within the global declarations???

Thanks again.
 
Level 6
Joined
Jul 5, 2021
Messages
11
JASS:
//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************
                     
globals
    /// integer                 tier                       = 0
        integer                 attackWave                 = 0
        integer                 nextDelay                  = 0
        integer                 awGold                     = 0
        integer                 awWood                     = 0
        /// King Heroes
        constant integer        SOVEREIGN                  = 'H01L'
        constant integer        MONARCH                    = 'HC18'
        constant integer        MAJESTY                    = 'H03I'
        /// Prince Heroes
    /// constant integer        PALADIN                    = 'Hpal'
        constant integer        MAGE                       = 'H01G'
        constant integer        WARRIOR                    = 'H03J'
        /// King Hero Abilities
        constant integer        ROYAL_BANISH               = 'A006'
        constant integer        KING_AURA                  = 'A00K'
        constant integer        KING_COURT                 = 'A00C'
    /// constant integer        THUNDER_CLAP               = 'AHtc' /// Sovereign only / "Royal Revenge"
        constant integer        ROYAL_SHOCKWAVE            = 'A06G' /// Monarch only
        constant integer        ROYAL_BLIZZARD             = 'A06H' /// Majesty only
        constant integer        ROYAL_SUMMON               = 'A01H' /// based on blizzard spell so ais tend to use improperly
        /// Prince Hero Abilities
    /// constant integer        HOLY_BOLT                  = 'AHhb' /// Holy Light / "Royal Blessing"     
    /// constant integer        BLINK                      = 'AEbl' /// Royal Mage only
    /// constant integer        DIVINE_SHIELD              = 'AHds' /// Royal Pally only
    /// constant integer        DEVOTION_AURA              = 'AHad'
        constant integer        MASS_REZ                   = 'A06E' /// Royal Pally only
    /// constant integer        MASS_TELEPORT              = 'AHmt' /// Royal Mage only
        constant integer        ATTRIBUTE_BONUS            = 'Aamk'
        constant integer        FERAL_IMPACT               = 'A01U' /// Royal Warrior only
        constant integer        CRIT_STRIKE                = 'A06K' /// Royal Warrior only
        constant integer        ROYAL_AVATAR               = 'A06I' /// Royal Warrior only
        constant integer        BLADESTORM                 = 'A06J' /// Royal Warrior only
        /// Buildings               
    /// constant integer        CASTLE                     = 'hcas'
    /// constant integer        TOWN_HALL                  = 'htow'
    /// constant integer        LUMBER_MILL                = 'hlum' /// already set in J file, will this be a problem?
    /// constant integer        BLACKSMITH                 = 'hbla'
        constant integer        ROYAL_BARRACKS             = 'H02P'
        constant integer        FARM_1                     = 'h003'
        constant integer        FARM_2                     = 'h005'
        constant integer        FARM_3                     = 'h006'
        constant integer        FARM_4                     = 'h007'
        constant integer        FARM_5                     = 'h00S'
    /// constant integer        BARRACKS                   = 'hbar' /// "Stables" (tier 1) defined as Barracks in .j file
        constant integer        STABLES_2                  = 'h00A'
        constant integer        STABLES_3                  = 'h00B'
        constant integer        STABLES_4                  = 'h00K'
        constant integer        GARRISON_1                 = 'h00F'
        constant integer        GARRISON_2                 = 'h00G'
        constant integer        GARRISON_3                 = 'h00H'
        constant integer        ROYAL_FACTORY              = 'h01F'
        constant integer        RESEARCH_CENTER_1          = 'h01H'
        constant integer        RESEARCH_CENTER_2          = 'h02Q'
        constant integer        FOUNTAIN                   = 'n020'
        constant integer        ROYAL_SHIPYARD             = 'h01S'
        constant integer        STONEMASON_TOWER           = 'h02Y'
        constant integer        ROYAL_WORKSHOP             = 'h02Z'
        constant integer        FARM_COTTAGE               = 'h034'
    /// constant integer        SANCTUM                    = 'hars' /// "Tower of Wizardry"
        constant integer        TOWER_WIZARDRY_2_BUILT     = 'h031'
        constant integer        TOWER_WIZARDRY_2_UPGRADE   = 'h03H'
        constant integer        ROYAL_CHURCH               = 'h01A'
    /// constant integer        ARCANE_VAULT               = 'hvlt' /// "Royal Market" (tier 1)
        constant integer        ROYAL_MARKET_2             = 'h01K'
        constant integer        TOWER_BASIC                = 'h03X'
    /// constant integer        GUARD_TOWER                = 'hgtw' /// "Guard Tower" (tier 1)
        constant integer        GUARD_TOWER_2              = 'h00Q'
        constant integer        GUARD_TOWER_3              = 'h00P'
    /// constant integer        CANNON_TOWER               = 'hctw' /// "Cannon Tower" (tier 1)
        constant integer        CANNON_TOWER_2             = 'h033'
    /// constant integer        ARCANE_TOWER               = 'hatw' /// "Arcane Tower" (tier 1)
        constant integer        ARCANE_TOWER_2             = 'h018'  
        constant integer        ARCANE_TOWER_3             = 'h02V'    
        constant integer        TOWER_COLD_1               = 'ndt1'
        constant integer        TOWER_COLD_2               = 'ndt2'
        constant integer        TOWER_COLD_3               = 'n01H'
        constant integer        TOWER_COLD_4               = 'n01I'
        constant integer        TOWER_FLAME_1              = 'nft1'
        constant integer        TOWER_FLAME_2              = 'nft2'
        constant integer        TOWER_FLAME_3              = 'n029'
        constant integer        TOWER_FLAME_4              = 'n02A'
        constant integer        TOWER_FLAME_5              = 'n02B'
        constant integer        TOWER_FLAME_6              = 'n02C'
        constant integer        TOWER_ROYAL_1              = 'hC17'
        constant integer        TOWER_ROYAL_2              = 'h000'
        constant integer        TOWER_ROYAL_3              = 'h001'
        constant integer        TOWER_ROYAL_4              = 'h00C'
        constant integer        TOWER_ROYAL_SKY            = 'n00D'
    
    endglobals

I checked with a Syntax Checker, and it said that "Avatar" was already taken, prob from the Mountain King.

It also said that no other Syntax Errors were found, which is good.

Anyways, i changed it to ROYAL_AVATAR, that should fix the issue ;)
 
Level 18
Joined
Mar 16, 2008
Messages
721
thank you that seemed to be the problem. Also before the last test I changed one of the init options, which is a terrible idea when trying to debug, but when i changed that back and fixed the duplicate constant you pointed out, it worked. Sorry I should have caught the duplicate constants myself. Thank you so much.
 
Status
Not open for further replies.
Top