HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Function Problem

02-24-2007, 11:03 PM#1
Preskooldude
I have a problem with a certain JASS trigger I am creating.

For some odd reason, when I put the following script:
Collapse JASS:
function Movement takes nothing returns nothing
    //Locals
    local real TempX                    //Used for the temporary
    local real TempY                    //point.
    local location TempPoint
    //----------SNIP-------------
    //Find the direction to travel in by making a temporary point
    if udg_KeyUp[ Index ] == true then
        set TempY = GetUnitY( udg_PlayerUnit[ Index ] ) + 100
    endif
    if udg_KeyRight[ Index ] == true then
        set TempX = GetUnitX( udg_PlayerUnit[ Index ] ) + 100
    endif
    //------------SNIP-----------
    //Order the unit to move there
    //-----------------------------------ERROR------------------------
    call IssuePointOrder( udg_PlayerUnit[ Index ], "move", TempX, TempY )
    //----------------------------------ERROR-------------------------
endfunction
in the compiler AND JASSCraft, it comes up clean. But in the game, it complains that "tempY" was never initialized in function "Movement".
I know its the line I outlined with ---ERROR--- because when I commented it out, it went along fine. So does anyone have an idea of why its complaining?
EDIT: Nvm... it was complaining because the locals weren't initialized to a value.
02-25-2007, 12:13 AM#2
Joker
If your udg_KeyUp[ Index ] and udg_KeyRight[ Index ] dont return true, then your variables would never be initialized.
02-25-2007, 07:52 AM#3
Mythic Fr0st
What is the variable "Index" I see no declaration of this?

Collapse JASS:
function Movement takes nothing returns nothing
    //Locals
    local real TempX = 0                   //Used for the temporary
    local real TempY = 0                    //point.
    local location TempPoint
    local integer Index = 0 //What is index suppost to be?
    //----------SNIP-------------
    //Find the direction to travel in by making a temporary point
    if udg_KeyUp[Index] == true then
        set TempY = GetUnitY(udg_PlayerUnit[Index]) + 100
    endif
    if udg_KeyRight[Index] == true then
        set TempX = GetUnitX(udg_PlayerUnit[Index]) + 100
    endif
    //------------SNIP-----------
    //Order the unit to move there
    //-----------------------------------ERROR------------------------
    call IssuePointOrder(udg_PlayerUnit[Index], "move", TempX, TempY )
    //----------------------------------ERROR-------------------------
endfunction

Spaces are not needed, and Index, is not a variable, you may have put Index instead of udg_Index, or just forgot to declare Index?

Is that a mistake?
02-25-2007, 11:48 AM#4
Preskooldude
Read back to the first post please, its already been fixed.
I snipped out the lines pertaining to Index, which checks the index number of the expired trigger according to its position in a global array (Corresponding to the player number, you see).
Also Joker, the global variables KeyUp and KeyLeft were set somewhere else.