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

[vJASS] Global doesn't get initialized

Status
Not open for further replies.
Level 45
Joined
Feb 27, 2007
Messages
5,578
I have this in some code and I don't know why they're not getting set. I thought it was the constant keyword but I removed that and it's still happening. I have to set them manually in an init function.
JASS:
globals
    private constant integer NEXT_ORD = OrderId("rainoffire")
    private          integer CNCL_ORD = OrderId("taunt")
    private constant integer BUFF_ORD = OrderId("cripple")
endglobals
//run long after map init
call BJDebugMsg(I2S(CNCL_ORD)) //returns 0
set CNCL_ORD = OrderId("taunt")
call BJDebugMsg(I2S(CNCL_ORD)) //returns the right number
 
From the JassHelper manual:

...you can't make them initialize with any function call or with a native (although it is possible to use a native, most natives tend to crash the thread when used in globals declaration).

This could be the case. You're better off using the actual integers instead of the strings. Bookmark this thread (;
 
Level 13
Joined
Nov 7, 2014
Messages
571
The OrderId's lookup table (assuming that's how it's implemented) is probably populated at some point when the config/main functions are called. But globals are initialized before that, i.e OrderId's table is empty at that point. That's just my guess.

Anyway, why not use the integer value directly instead?

JASS:
globals
    private constant integer ORDER_ID_RAIN_OF_FIRE = 852238
    private constant integer ORDER_ID_TAUNT = 852520
    private constant integer ORDER_ID_CRIPPLE = 852189
endglobals

Besides OrderId doesn't know about these order-ids for example:
JASS:
    // When player drags item to slot XX.
    ORDER_ID_ITEM_DRAG_00 = 852002
    ORDER_ID_ITEM_DRAG_01 = 852003
    ORDER_ID_ITEM_DRAG_02 = 852004
    ORDER_ID_ITEM_DRAG_03 = 852005
    ORDER_ID_ITEM_DRAG_04 = 852006
    ORDER_ID_ITEM_DRAG_05 = 852007

    // When player uses item in slot XX.
    ORDER_ID_ITEM_USE_00  = 852008
    ORDER_ID_ITEM_USE_01  = 852009
    ORDER_ID_ITEM_USE_02  = 852010
    ORDER_ID_ITEM_USE_03  = 852011
    ORDER_ID_ITEM_USE_04  = 852012
    ORDER_ID_ITEM_USE_05  = 852013

PS: there's this list of order-ids in this thread from wc3c.net
 
Status
Not open for further replies.
Top