HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Uniniltilized Variable?

02-07-2007, 01:24 AM#1
Joker
Sorry about the spelling, but what does that mean? How can you fix it? Its coming up on a couple of my locals..

heres one of them
Collapse JASS:
    local player aa
    local integer a

    loop
        exitwhen a == 12
        set aa = Player(a)
        if GetPlayerSlotState(aa) == PLAYER_SLOT_STATE_EMPTY then
            call MultiboardSetItemValueBJ( udg_Multiboard, 1, GetPlayerId(aa) + 2, "|c00959697" + "<<Empty>>" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 2, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 3, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 4, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
        endif
        set a = a + 1
    endloop
02-07-2007, 01:26 AM#2
wyrmlord
I'm not sure exactly what you mean. Perhaps you should post some code?
02-07-2007, 01:32 AM#3
Rising_Dusk
Collapse JASS:
local integer a = 0
That will fix it.

It means you were using a variable without ever setting it equal to something.
02-08-2007, 09:14 PM#4
Joker
Why do I have to have the local set to something with it when i delare it instead of declaring the local later on in the trigger??
02-08-2007, 09:27 PM#5
Rising_Dusk
You can declare it later if you want.
It just saves a line of code to initialize it right away.

Collapse JASS:
    local integer a

    loop
        exitwhen a == 12
        set aa = Player(a)
        if GetPlayerSlotState(aa) == PLAYER_SLOT_STATE_EMPTY then
            call MultiboardSetItemValueBJ( udg_Multiboard, 1, GetPlayerId(aa) + 2, "|c00959697" + "<<Empty>>" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 2, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 3, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 4, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
        endif
        set a = a + 1
    endloop
The portion in red is setting the value in 'a' to the value of 'a' + 1.
Note, before you've initialized the variable, 'a' has no value.
Therefore how can you add 1 to a nonexistent number?
You can't, ergo the error.

You could solve it a few ways, as shown below.
Collapse JASS:
    local integer a = 0

    loop
        exitwhen a == 12
        set aa = Player(a)
        if GetPlayerSlotState(aa) == PLAYER_SLOT_STATE_EMPTY then
            call MultiboardSetItemValueBJ( udg_Multiboard, 1, GetPlayerId(aa) + 2, "|c00959697" + "<<Empty>>" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 2, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 3, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 4, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
        endif
        set a = a + 1
    endloop
Collapse JASS:
    local integer a

    set a = 0
    loop
        exitwhen a == 12
        set aa = Player(a)
        if GetPlayerSlotState(aa) == PLAYER_SLOT_STATE_EMPTY then
            call MultiboardSetItemValueBJ( udg_Multiboard, 1, GetPlayerId(aa) + 2, "|c00959697" + "<<Empty>>" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 2, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 3, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
            call MultiboardSetItemValueBJ( udg_Multiboard, 4, GetPlayerId(aa) + 2, "|c00959697" + "--" + "|r" )
        endif
        set a = a + 1
    endloop