• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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

Status
Not open for further replies.
Level 17
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 17
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