| 09-15-2009, 07:54 PM | #1 |
Hey out of curiosity I was wondering if someone might have the solution to my problem. I currently have an array of units and it is set when I create units. I did a BJDebugMsg right after and it showed that the unit was stored in the slot. However, my other triggers are finding it as null. Even my test trigger that just loops through and displays something, by pressing esc, if its not null has them as null. I have nothing setting the array to null. Does anyone have any idea what the problem might be, or should I upload my map or script? Sorry if I'm lacking any info you need. |
| 09-15-2009, 08:07 PM | #2 | |
Quote:
Posting the relevant code between [jass][/jass] or [trigger][/trigger] tags should be enough. |
| 09-15-2009, 09:24 PM | #3 |
Well my code isn't in VJass, and I'm sorry. I will explain the global variables for ya. I know reading regular JASS is a pain, so I will understand if your like bleh no way. udg_thrown is an array for each player that checks if the player casted the spell. udg_boomerangs is an array that stores each player's boomerang. udg_move is anb array counter for how many times the boomerang has moved for each player. udg_return is an array that checks if the boomerang is ready to return or not. udg_wardens is an array that stores the casters of each spell. (It is set when the unit is created) udg_big is an array that stores if big powerup was used. udg_quick is an array that stores if quick powerup was used. udg_long is an array that stores if long powerup was used. udg_invisible is an array that stores if invisible powerup was used. udg_double is an array that stores if double powerup was used. I have two of the same functions one using loops and one using ForGroup. I wasn't sure which one was better. I will post both. This first function is when the spell is casted: JASS:function Throw takes nothing returns nothing local unit t = GetTriggerUnit() local unit boomerang = null local integer i = GetPlayerId(GetOwningPlayer(t)) local real x = GetUnitX(t) local real y = GetUnitY(t) local real spellX = GetSpellTargetX() local real spellY = GetSpellTargetY() if(GetSpellAbilityId() == 'A001') then set udg_return[i] = false if(udg_big[i] == false) then //Create normal boomerang set boomerang = CreateUnit(GetOwningPlayer(t), 'h000', x, y, AngleBetweenReals(x, spellX, y, spellY)) else //Create big boomerang set boomerang = CreateUnit(GetOwningPlayer(t), 'h002', x, y, AngleBetweenReals(x, spellX, y, spellY)) endif set udg_boomerangs[i] = boomerang call GroupAddUnit(udg_allBoomerangs, boomerang) if(udg_FFA == false and IsPlayerInForce(Player(i), udg_team1) == true) then //Change Unit to team 1 call SetUnitColor(boomerang, udg_teamColor1) elseif(udg_FFA == false and IsPlayerInForce(Player(i), udg_team2) == true) then //Change Unit to team 2 call SetUnitColor(boomerang, udg_teamColor2) endif set udg_thrown[i] = true set udg_moved[i] = 0 call UnitRemoveAbility(t, 'A001') call UnitAddAbility(t, 'A002') call UnitAddAbility(boomerang, 'Aloc') endif set t = null set boomerang = null endfunction //=========================================================================== function InitTrig_Throw_Boomerang takes nothing returns nothing local integer i = 0 set gg_trg_Throw_Boomerang = CreateTrigger( ) loop call TriggerRegisterPlayerUnitEvent( gg_trg_Throw_Boomerang, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null ) set i = i + 1 exitwhen i > 11 endloop call TriggerAddAction( gg_trg_Throw_Boomerang, function Throw ) endfunction This next one is moving the boomerang with loops: JASS:function MoveAllBoomerangs takes nothing returns nothing local real x = 0.0 local real y = 0.0 local integer i = 0 local integer i2 = 0 local unit boomerang = null local unit warden = null local unit attacked = null local multiboarditem mbitem = null loop if( udg_thrown[i] == true) then set boomerang = udg_boomerangs[i] set warden = udg_wardens[i] set x = GetUnitX(boomerang) set y = GetUnitY(boomerang) set i2 = 0 loop //Check Distance set attacked = udg_wardens[i2] if(attacked != null) then if(onSameTeam(Player(i), Player(i2)) == false) then //Checks if ally if(DistanceBetweenUnits(boomerang, attacked) <= 130 and i != i2 and udg_dead[i2] == false and udg_left[i2] == false and udg_invulnerble[i2] == false and udg_big[i] == false) then //Normal Boomerang set udg_dead[i2] = true if(udg_double[i] == false) then //Normal Points set udg_points[i] = udg_points[i] + 1 else //Double Points set udg_points[i] = udg_points[i] + 2 endif if(udg_Type == "Lives") then set udg_livesLeft[i2] = udg_livesLeft[i2] - 1 endif if(udg_Type == "Lives") then //Subtract set mbitem = MultiboardGetItem(udg_mb, udg_spot[i2], 1) call MultiboardSetItemValue(mbitem, udg_colors[i2] + I2S(udg_livesLeft[i2])) else //Add set mbitem = MultiboardGetItem(udg_mb, udg_spot[i], 1) call MultiboardSetItemValue(mbitem, udg_colors[i] + I2S(udg_points[i])) endif call MultiboardReleaseItem(mbitem) call SetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD) + 1) call DisplayTimedTextToPlayer(Player(i), 0, 0, 5.0, "You have killed " + udg_colors[i2] + GetPlayerName(Player(i2)) + ".") call DisplayTimedTextToPlayer(Player(i2), 0, 0, 5.0, "You were killed by " + udg_colors[i] + GetPlayerName(Player(i)) + ".") if(udg_points[i] >= udg_victory and udg_Type == "Points") then call GameOver(Player(i), attacked) endif if(AllDead() == true and udg_Type == "Lives") then call GameOver(Player(i), attacked) endif call KillUnit(attacked) if(udg_livesLeft[i2] > 0 and udg_Type == "Lives") then call TimerStart( udg_resTimer[i2], 5.0, false, null ) elseif(udg_livesLeft[i2] <= 0 and udg_Type == "Lives") then call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, udg_colors[i2] + GetPlayerName(Player(i2)) + "|r has been eliminated.") elseif(udg_Type == "Points" or udg_Type == "Timed") then call TimerStart( udg_resTimer[i2], 5.0, false, null ) endif elseif(DistanceBetweenUnits(boomerang, attacked) <= 140 and i != i2 and udg_dead[i2] == false and udg_left[i2] == false and udg_invulnerble[i2] == false and udg_big[i] == true) then //Big Boomerang set udg_dead[i2] = true if(udg_double[i] == false) then //Normal Points set udg_points[i] = udg_points[i] + 1 else //Double Points set udg_points[i] = udg_points[i] + 2 endif if(udg_Type == "Lives") then set udg_livesLeft[i2] = udg_livesLeft[i2] - 1 endif if(udg_Type == "Lives") then //Subtract set mbitem = MultiboardGetItem(udg_mb, udg_spot[i2], 1) call MultiboardSetItemValue(mbitem, udg_colors[i2] + I2S(udg_livesLeft[i2])) else //Add set mbitem = MultiboardGetItem(udg_mb, udg_spot[i], 1) call MultiboardSetItemValue(mbitem, udg_colors[i] + I2S(udg_points[i])) endif call MultiboardReleaseItem(mbitem) call SetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD) + 1) call DisplayTimedTextToPlayer(Player(i), 0, 0, 5.0, "You have killed " + udg_colors[i2] + GetPlayerName(Player(i2)) + ".") call DisplayTimedTextToPlayer(Player(i2), 0, 0, 5.0, "You were killed by " + udg_colors[i] + GetPlayerName(Player(i)) + ".") if(udg_points[i] >= udg_victory and udg_Type == "Points") then call GameOver(Player(i), attacked) endif if(AllDead() == true and udg_Type == "Lives") then call GameOver(Player(i), attacked) endif call KillUnit(attacked) if(udg_livesLeft[i2] > 0 and udg_Type == "Lives") then call TimerStart( udg_resTimer[i2], 5.0, false, null ) elseif(udg_livesLeft[i2] <= 0 and udg_Type == "Lives") then call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, udg_colors[i2] + GetPlayerName(Player(i2)) + "|r has been eliminated.") elseif(udg_Type == "Points" or udg_Type == "Timed") then call TimerStart( udg_resTimer[i2], 5.0, false, null ) endif endif endif endif set i2 = i2 + 1 exitwhen i2 > 7 endloop if( udg_return[i] == false) then //Move boomerang away if(udg_quick[i] == false) then //Normal boomerang away call PolarReal(boomerang, x, y, 30.7, GetUnitFacing(boomerang) + 360) else //Quick boomerang away call PolarReal(boomerang, x, y, 40.0, GetUnitFacing(boomerang) + 360) endif set udg_moved[i] = udg_moved[i] + 1 if(udg_moved[i] >= 23 and udg_long[i] == false and udg_quick[i] == false) then //Allow return of boomerang with no powerup set udg_return[i] = true elseif(udg_moved[i] >= 34 and udg_long[i] == true and udg_quick[i] == false) then //Allow return of boomerang with long powerup set udg_return[i] = true elseif(udg_moved[i] >= 18 and udg_long[i] == false and udg_quick[i] == true) then //Allow return of boomerang with quick powerup set udg_return[i] = true endif else //Return boomerang if(udg_quick[i] == false) then //Normal boomerang return call Polar(boomerang, 30.7, AngleBetweenUnits(boomerang, warden) + 360) else call Polar(boomerang, 40.0, AngleBetweenUnits(boomerang, warden) + 360) endif if(DistanceBetweenUnits(boomerang, warden) <= 75) then //Catch boomerang set udg_return[i] = false set udg_thrown[i] = false set udg_boomerangs[i] = null call RemoveUnit(boomerang) call UnitRemoveAbility(warden, 'A002') call UnitAddAbility(warden, 'A001') endif endif endif set i = i + 1 exitwhen i > 7 endloop set boomerang = null set attacked = null set warden = null set mbitem = null endfunction //=========================================================================== function InitTrig_Move_All_Boomerangs takes nothing returns nothing set gg_trg_Move_All_Boomerangs = CreateTrigger( ) call TriggerRegisterTimerEvent( gg_trg_Move_All_Boomerangs, 0.05, true ) call TriggerAddAction( gg_trg_Move_All_Boomerangs, function MoveAllBoomerangs ) endfunction Lastly the other option to moving the boomerang with ForGroup, they are never enabled at same time. Just was messing around, wasn't sure which was better. JASS:function MoveAllBoomerangs2 takes nothing returns nothing local real x = 0.0 local real y = 0.0 local integer i2 = 0 local unit boomerang = GetEnumUnit() local integer id = GetPlayerId(GetOwningPlayer(GetEnumUnit())) local unit warden = null local multiboarditem mbitem = null if( udg_thrown[id] == true) then set x = GetUnitX(boomerang) set y = GetUnitY(boomerang) set i2 = 0 loop //Check Distance set warden = udg_wardens[i2] if(warden != null and boomerang != null) then if(onSameTeam(Player(id), Player(i2)) == false) then //Checks if ally if(DistanceBetweenUnits(boomerang, warden) <= 130 and id != i2 and udg_dead[i2] == false and udg_left[i2] == false and udg_invulnerble[i2] == false and udg_big[id] == false) then //Normal Boomerang set udg_dead[i2] = true if(udg_double[id] == false) then //Normal Points set udg_points[id] = udg_points[id] + 1 else //Double Points set udg_points[id] = udg_points[id] + 2 endif if(udg_Type == "Lives") then set udg_livesLeft[i2] = udg_livesLeft[i2] - 1 endif if(udg_Type == "Lives") then //Subtract set mbitem = MultiboardGetItem(udg_mb, udg_spot[i2], 1) call MultiboardSetItemValue(mbitem, udg_colors[i2] + I2S(udg_livesLeft[i2])) else //Add set mbitem = MultiboardGetItem(udg_mb, udg_spot[id], 1) call MultiboardSetItemValue(mbitem, udg_colors[id] + I2S(udg_points[id])) endif call MultiboardReleaseItem(mbitem) call SetPlayerState(Player(id), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(id), PLAYER_STATE_RESOURCE_GOLD) + 1) call DisplayTimedTextToPlayer(Player(id), 0, 0, 5.0, "You have killed " + udg_colors[i2] + GetPlayerName(Player(i2)) + ".") call DisplayTimedTextToPlayer(Player(i2), 0, 0, 5.0, "You were killed by " + udg_colors[id] + GetPlayerName(Player(id)) + ".") if(udg_points[id] >= udg_victory and udg_Type == "Points") then call GameOver(Player(id), warden) endif if(AllDead() == true and udg_Type == "Lives") then call GameOver(Player(id), warden) endif call KillUnit(warden) if(udg_livesLeft[i2] > 0 and udg_Type == "Lives") then call TimerStart( udg_resTimer[i2], 5.0, false, null ) elseif(udg_livesLeft[i2] <= 0 and udg_Type == "Lives") then call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, udg_colors[i2] + GetPlayerName(Player(i2)) + "|r has been eliminated.") elseif(udg_Type == "Points" or udg_Type == "Timed") then call TimerStart( udg_resTimer[i2], 5.0, false, null ) endif elseif(DistanceBetweenUnits(boomerang, warden) <= 140 and id != i2 and udg_dead[i2] == false and udg_left[i2] == false and udg_invulnerble[i2] == false and udg_big[id] == true) then //Big Boomerang set udg_dead[i2] = true if(udg_double[id] == false) then //Normal Points set udg_points[id] = udg_points[id] + 1 else //Double Points set udg_points[id] = udg_points[id] + 2 endif if(udg_Type == "Lives") then set udg_livesLeft[i2] = udg_livesLeft[i2] - 1 endif if(udg_Type == "Lives") then //Subtract set mbitem = MultiboardGetItem(udg_mb, udg_spot[i2], 1) call MultiboardSetItemValue(mbitem, udg_colors[i2] + I2S(udg_livesLeft[i2])) else //Add set mbitem = MultiboardGetItem(udg_mb, udg_spot[id], 1) call MultiboardSetItemValue(mbitem, udg_colors[id] + I2S(udg_points[id])) endif call MultiboardReleaseItem(mbitem) call SetPlayerState(Player(id), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(id), PLAYER_STATE_RESOURCE_GOLD) + 1) call DisplayTimedTextToPlayer(Player(id), 0, 0, 5.0, "You have killed " + udg_colors[i2] + GetPlayerName(Player(i2)) + ".") call DisplayTimedTextToPlayer(Player(i2), 0, 0, 5.0, "You were killed by " + udg_colors[id] + GetPlayerName(Player(id)) + ".") if(udg_points[id] >= udg_victory and udg_Type == "Points") then call GameOver(Player(id), warden) endif if(AllDead() == true and udg_Type == "Lives") then call GameOver(Player(id), warden) endif call KillUnit(warden) if(udg_livesLeft[i2] > 0 and udg_Type == "Lives") then call TimerStart( udg_resTimer[i2], 5.0, false, null ) elseif(udg_livesLeft[i2] <= 0 and udg_Type == "Lives") then call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, udg_colors[i2] + GetPlayerName(Player(i2)) + "|r has been eliminated.") elseif(udg_Type == "Points" or udg_Type == "Timed") then call TimerStart( udg_resTimer[i2], 5.0, false, null ) endif endif endif endif set i2 = i2 + 1 exitwhen i2 > 7 endloop set id = GetPlayerId(GetOwningPlayer(GetEnumUnit())) set warden = udg_wardens[id] if( udg_return[id] == false) then //Move boomerang away if(udg_quick[id] == false) then //Normal boomerang away call PolarReal(boomerang, x, y, 30.7, GetUnitFacing(boomerang) + 360) else //Quick boomerang away call PolarReal(boomerang, x, y, 40.0, GetUnitFacing(boomerang) + 360) endif set udg_moved[id] = udg_moved[id] + 1 if(udg_moved[id] >= 23 and udg_long[id] == false and udg_quick[id] == false) then //Allow return of boomerang with no powerup set udg_return[id] = true elseif(udg_moved[id] >= 34 and udg_long[id] == true and udg_quick[id] == false) then //Allow return of boomerang with long powerup set udg_return[id] = true elseif(udg_moved[id] >= 18 and udg_long[id] == false and udg_quick[id] == true) then //Allow return of boomerang with quick powerup set udg_return[id] = true endif else //Return boomerang if(udg_quick[id] == false) then //Normal boomerang return call Polar(boomerang, 30.7, AngleBetweenUnits(boomerang, warden) + 360) else call Polar(boomerang, 40.0, AngleBetweenUnits(boomerang, warden) + 360) endif if(DistanceBetweenUnits(boomerang, warden) <= 75) then //Catch boomerang set udg_return[id] = false set udg_thrown[id] = false set udg_boomerangs[id] = null call GroupRemoveUnit(udg_allBoomerangs, boomerang) call RemoveUnit(boomerang) call UnitRemoveAbility(warden, 'A002') call UnitAddAbility(warden, 'A001') endif endif endif set boomerang = null set warden = null set mbitem = null endfunction function AllBoomerangs takes nothing returns nothing call ForGroup(udg_allBoomerangs, function MoveAllBoomerangs2) endfunction //=========================================================================== function InitTrig_Move_All_Boomerangs_2 takes nothing returns nothing set gg_trg_Move_All_Boomerangs_2 = CreateTrigger( ) call TriggerRegisterTimerEvent( gg_trg_Move_All_Boomerangs_2, 0.05, true ) call TriggerAddAction( gg_trg_Move_All_Boomerangs_2, function AllBoomerangs ) endfunction |
| 09-16-2009, 04:52 AM | #4 |
I'm guessing that GetTriggerUnit() returns null in the casting trigger. You should use GetSpellAbilityUnit() instead, I think. EDIT: or maybe not... |
| 09-16-2009, 10:37 AM | #5 |
The first one works fine, the last two do not. Sorry for making it confusing :(. |
| 09-16-2009, 12:17 PM | #6 |
first, try resetting i2 to 0 after youre out of your nested loop. nevermind. Are you absolutely sure that this is all code that could possibly set udg_boomerang to null? |
| 09-16-2009, 07:43 PM | #7 |
Try disabling the section that "catches" the boomerang. The distance-between-points calculation might be such that the boomerang is destroyed (and the variable nulled) on the first iteration. |
| 09-17-2009, 02:13 AM | #8 |
I'm sorry once again, it is not the boomerang that is going null. It is the udg_wardens array that is going null. Sorry I'm terrible with explaining, and don't mean to be a pain. |
