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

[JASS] Says not initialized in game but i did...

Status
Not open for further replies.
Level 18
Joined
Sep 2, 2005
Messages
1,029
JASS:
function Trig_Hes_Baaaaack_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'e008' ) and not ( GetUnitTypeId(GetTriggerUnit()) == 'e007' ) and not ( GetUnitTypeId(GetTriggerUnit()) == 'e006' ) and not ( GetUnitTypeId(GetTriggerUnit()) == 'e005' )) then
        return false
    endif
    return true
endfunction

function Trig_Hes_Baaaaack_Actions takes nothing returns nothing
    local player whichPlayer= GetTriggerPlayer()
    local group roots
    local unit root
    local integer id = GetUnitTypeId(root)
    local location rootLoc
    local real rootX
    local real rootY
    set roots = GetUnitsOfPlayerAndTypeId(whichPlayer, 'e00D')
    call GroupAddGroup(GetUnitsOfPlayerAndTypeId(whichPlayer, 'e00G'), roots)
    call GroupAddGroup(GetUnitsOfPlayerAndTypeId(whichPlayer, 'e00R'), roots)
    call GroupAddGroup(GetUnitsOfPlayerAndTypeId(whichPlayer, 'e00Q'), roots)
    set root = GroupPickRandomUnit(roots)
    set rootLoc = GetUnitLoc(root)
    set rootX=GetLocationX(rootLoc)
    set rootY=GetLocationY(rootLoc)
    

    if (id == 'e00D') then
        call CreateUnitAtLoc(whichPlayer, 'e001', rootLoc, bj_UNIT_FACING)
        call SelectUnitForPlayerSingle( FirstOfGroup(GetUnitsOfPlayerAndTypeId(whichPlayer, 'e001')), whichPlayer )
        call SetCameraPositionForPlayer(whichPlayer, rootX, rootY)
        call SetCameraQuickPositionForPlayer(whichPlayer, rootX, rootY) 
    elseif (id == 'e00G') then
        call CreateUnitAtLoc(whichPlayer, 'e002', rootLoc, bj_UNIT_FACING)
        call SelectUnitForPlayerSingle( FirstOfGroup(GetUnitsOfPlayerAndTypeId(whichPlayer, 'e002')), whichPlayer )
        call SetCameraPositionForPlayer(whichPlayer, rootX, rootY)
        call SetCameraQuickPositionForPlayer(whichPlayer, rootX, rootY) 
    elseif (id == 'e00R') then
        call CreateUnitAtLoc(whichPlayer, 'e003', rootLoc, bj_UNIT_FACING)
        call SelectUnitForPlayerSingle( FirstOfGroup(GetUnitsOfPlayerAndTypeId(whichPlayer, 'e003')), whichPlayer )
        call SetCameraPositionForPlayer(whichPlayer, rootX, rootY)
        call SetCameraQuickPositionForPlayer(whichPlayer, rootX, rootY) 
    elseif (id == 'e00Q') then
        call CreateUnitAtLoc(whichPlayer, 'e004', rootLoc, bj_UNIT_FACING)
        call SelectUnitForPlayerSingle( FirstOfGroup(GetUnitsOfPlayerAndTypeId(whichPlayer, 'e004')), whichPlayer )
        call SetCameraPositionForPlayer(whichPlayer, rootX, rootY)
        call SetCameraQuickPositionForPlayer(whichPlayer, rootX, rootY)   
    endif

    //cleanup
    call KillUnit(root)
    call RemoveUnit(root)
    set root = null
    call DestroyGroup(roots)
    set roots= null
endfunction

//===========================================================================
function InitTrig_Hes_Baaaaack takes nothing returns nothing
    set gg_trg_Hes_Baaaaack = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Hes_Baaaaack, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Hes_Baaaaack, Condition( function Trig_Hes_Baaaaack_Conditions ) )
    call TriggerAddAction( gg_trg_Hes_Baaaaack, function Trig_Hes_Baaaaack_Actions )
endfunction

It compiles fine, but in game, when the script is called, it says that root is not initialized. Isn't that what I did when I declared it and then set it with this? "set root = GroupPickRandomUnit(roots)"
 
Level 18
Joined
Sep 2, 2005
Messages
1,029
the problem lies at local integer id = GetUnitTypeId(root)

So before setting roots = a group and root = a random unit of the group, you set id = GetUnitTypeId(unitinitalised root)

Problem solved.

I hate how often I miss these little, obvious errors. Sometimes you just need someone who didn't write it to look at it and see what you miss because you know what you meant. like in an essay. Thanks.
 
Status
Not open for further replies.
Top