[Solved] function stuck at unknown location

Status
Not open for further replies.
Level 12
Joined
Jun 15, 2016
Messages
472
Hello Hive,

I'm trying to create a trigger which decides which player has the most units in 4 regions. So far my trigger looks like this:


JASS:
function Update_COP_Command takes player p, integer i returns nothing
   if p == Player(PLAYER_NEUTRAL_AGGRESSIVE) then
       call CommandAI(Player(1),13,i)
   elseif p == Player(1) then
       call CommandAI(Player(1),12,i)
   elseif p == Player(0) then
       call CommandAI(Player(1),11,i)
   endif
endfunction

function Set_COP_Owner takes group COP_Surrounding returns player
   local integer CruUnits = 0
   local integer ForUnits = 0
   local integer NeuUnits = 0
   local unit tempunit
   
   call BJDebugMsg("test")

   if IsUnitGroupEmptyBJ(COP_Surrounding) then // group is empty
       call BJDebugMsg("Group empty")
       
       call DestroyGroup(COP_Surrounding)
       return Player(PLAYER_NEUTRAL_AGGRESSIVE)
   else // group is not empty,check units
       loop
           set tempunit = FirstOfGroup(COP_Surrounding)
           exitwhen tempunit == null
           if GetOwningPlayer(FirstOfGroup(COP_Surrounding)) == Player(0) then
               set ForUnits = ForUnits + 1
               call GroupRemoveUnit(COP_Surrounding,tempunit)
           elseif GetOwningPlayer(FirstOfGroup(COP_Surrounding)) == Player(1) then
               set CruUnits = CruUnits + 1
               call GroupRemoveUnit(COP_Surrounding,tempunit)
           else //Unit is neutral or  other player
               set NeuUnits = NeuUnits + 1
               call GroupRemoveUnit(COP_Surrounding,tempunit)
           endif
           
           call BJDebugMsg(("Crusader units: " + I2S(CruUnits) + "|| Forsaken units: " + I2S(ForUnits) + "|| Neutral units: " + I2S(NeuUnits)))
       endloop
   endif
   set tempunit = null
   call DestroyGroup(COP_Surrounding)
   
   if (ForUnits > CruUnits) and (ForUnits > NeuUnits) then
       return Player(0)
   elseif (CruUnits > ForUnits) and (CruUnits > NeuUnits) then
       return Player(1)
   else // COP owner is neutral or undefined
       return Player(PLAYER_NEUTRAL_AGGRESSIVE)
   endif
endfunction

function Trig_COP_Owner_loop_Actions takes nothing returns nothing
   local integer index = 0
   local group Current_COP_Units
   local player Current_COP_Owner
   
   call BJDebugMsg("Checking COP owners")
   
   loop
       exitwhen index > 3
       
       call GroupEnumUnitsInRect(Current_COP_Units,udg_SUR[index],null)
       set Current_COP_Owner = Set_COP_Owner(Current_COP_Units)
       
       if Current_COP_Owner != udg_COP_Owner[index] then
           call Update_COP_Command(Current_COP_Owner, index)
           set udg_COP_Owner[index] = Current_COP_Owner
           call BJDebugMsg("COP recieved new owner")
       endif // The owner is already declered, don't send command and don't overload ai script
       
       call BJDebugMsg(("COP" + I2S(index + 1) + "updated"))
       
       set index = index + 1
   endloop
   
   set Current_COP_Units = null
   set Current_COP_Owner = null
endfunction

//===========================================================================
function InitTrig_COP_Owner_loop takes nothing returns nothing
    set gg_trg_COP_Owner_loop = CreateTrigger(  )
    call TriggerAddAction( gg_trg_COP_Owner_loop, function Trig_COP_Owner_loop_Actions )
endfunction


As you can see I tried putting debug messages all over the place, and only the first one in Trig_COP_Owner_loop_Actions is displayed. The regions I'm checking all have about 4-6 units at the start.

Halpf
 
Status
Not open for further replies.
Top