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

Initialize Global arrays

Status
Not open for further replies.
Level 17
Joined
Mar 21, 2011
Messages
1,611
Hi guys!
i think i'm stuck in an easy problem :/
what i want to do is to create a global string array for each player (that has the player name in the correct player color saved in it)

the first thing i dont know, how to initialize those globals?

here is my trigger
JASS:
library YourScope initializer Init

    private function Init takes nothing returns nothing
    
    
        local integer counter = 0

        
        globals
        
            set string udg_PlayerColor[0] = "|cffff0303"
            set string udg_PlayerColor[1] = "|cff0042ff"
            set string udg_PlayerName[]
            
        endglobals
        
        
        call FogMaskEnable(false)
        call FogEnable(false)
        call FogEnable(true)
    
        loop
            exitwhen counter >= 12
            
            call SetPlayerAbilityAvailable(Player(counter), 'A01X', false)
            set udg_PlayerName[counter] = udg_PlayerColor[counter] + GetPlayerName(Player(counter))
            
            set counter = counter + 1
        endloop
    
    
    endfunction

endlibrary
 
This is how it should look

JASS:
library YourScope initializer Init

    globals
        string array udg_PlayerColor
        string array udg_PlayerName
    endglobals
        
    private function Init takes nothing returns nothing
        local integer counter = 0
        
        set udg_PlayerColor[0] = "|cffff0303"
        set udg_PlayerColor[1] = "|cff0042ff"

        call FogMaskEnable(false)
        call FogEnable(false)
        call FogEnable(true)
    
        loop
            exitwhen counter >= 12
            
            call SetPlayerAbilityAvailable(Player(counter), 'A01X', false)
            set udg_PlayerName[counter] = udg_PlayerColor[counter] + GetPlayerName(Player(counter))
            
            set counter = counter + 1
        endloop

    endfunction

endlibrary
You could also consider PlayerUtils to handle player colors. You should also not be using the udg_ prefix.
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
it will always give me the error message, that it is not an array. i didnt create the variable in the variable editor, could that be the problem? cause i thought the variable editor has no usage in vjass


Edit:

Nevermind, i'm stupid as hell xD
thanks for helping me +rep
 
it will always give me the error message, that it is not an array. i didnt create the variable in the variable editor, could that be the problem? cause i thought the variable editor has no usage in vjass

The code I posted works perfectly, try again. You also should state what error, if any.

And no you do not need the variable editor.
 
Status
Not open for further replies.
Top