| 06-13-2006, 08:09 PM | #1 |
My trigger works, looping until the a stag comes into range (64 range). However, whenever one is saved, all currently dead stags are saved, despite all variables used being local variables. JASS:function IsStagBool takes nothing returns boolean if GetUnitTypeId(GetFilterUnit()) == 'u000' then if GetWidgetLife(GetFilterUnit()) > 0.405 then return true endif endif return false endfunction function Trig_Stag_Dies_Conditions takes nothing returns boolean return GetUnitTypeId(GetDyingUnit()) == 'u000' endfunction function Trig_Stag_Dies_Actions takes nothing returns nothing local player p = GetOwningPlayer(GetDyingUnit()) local real x = GetUnitX(GetDyingUnit()) local real y = GetUnitY(GetDyingUnit()) local unit u = CreateUnit(p, 'u001', x, y, GetUnitFacing(GetDyingUnit())) local group g = CreateGroup() local boolexpr b = Condition(function IsStagBool) call RemoveUnit(GetDyingUnit()) call GroupEnumUnitsInRect(g, GetPlayableMapRect(), b) if IsUnitGroupEmptyBJ(g) then call TriggerExecute( gg_trg_Victory ) endif call GroupClear(g) loop call GroupEnumUnitsInRange(g, x, y, 64, b) exitwhen (FirstOfGroup(g) == null) == false call GroupClear(g) call PolledWait(0.1) endloop if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then call DisplayTextToForce( GetPlayersAll(), ( GetPlayerName(GetOwningPlayer(u)) + " has been rescued." ) ) call CreateUnit(p, 'u000', x, y, GetUnitFacing(u)) call PingMinimapForForce( GetPlayersAll(), x, y, 3 ) endif call RemoveUnit(u) call DestroyBoolExpr(b) call DestroyGroup(g) set p = null set u = null set g = null endfunction //=========================================================================== function InitTrig_Stag_Dies takes nothing returns nothing set gg_trg_Stag_Dies = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Stag_Dies, EVENT_PLAYER_UNIT_DEATH ) call TriggerAddCondition( gg_trg_Stag_Dies, Condition( function Trig_Stag_Dies_Conditions ) ) call TriggerAddAction( gg_trg_Stag_Dies, function Trig_Stag_Dies_Actions ) endfunction Any ideas as to what is causing it? |
| 06-13-2006, 08:21 PM | #2 |
As a quick note: JASS:exitwhen (FirstOfGroup(g) == null) == false JASS:exitwhen (FirstOfGroup(g) != null) Are all these dead stags in the same place? |
| 06-13-2006, 08:46 PM | #3 | |
Quote:
No, they're not. It will still happen to all of them even if they are on the other side of the map from each other. And yes, there are a few things I could optimise a bit (one of my first pure JASS codes), but thanks for pointing it out. |
| 06-13-2006, 09:45 PM | #4 | |
That trigger runs for every stag that dies. So it has plenty of sense all of them are saved when a unit comes in range. You might want to do something so the detected unit is ignored later. Also there are some issues with the code, replace IsUnitGroupEmptyBJ(g) with a FirstOfGroup check , IsUnitGroupEmpty calls the count function (which is a long process) then compares the result with 0 , it is kind of lame. Quote:
Didn't note that, well this is weird, let me check again, -- Tried with a 10 for the range enum instead of 64? .. Also if you still think that the locals became non-local try to show a message "(x="+R2S(x)+","y="+R2S(y) whenever a stag is rescued |
| 06-14-2006, 11:58 AM | #5 | ||
Quote:
No, I'll give it a go, but I highly doubt it will make any difference. Quote:
Good idea, I'll put in some debug messages to show the state of the variables. EDIT: Solved the problem. Destroying the boolexpr destroyed it for all currently running triggers. Any ideas why? |
| 06-14-2006, 01:16 PM | #6 |
hmnn, could you show I2S(H2I(b) ) after the declaration of the boolexpr and see if they aren't equal? |
| 06-16-2006, 03:43 PM | #7 |
Perhaps all boolexpr's of a given function all point to the same thing? :S |
| 06-16-2006, 03:44 PM | #8 |
blizz wouldn't have made DestroyBoolExpr if that was true |
