Warcraft III resources & community, 2003–2006 · archived

Loop stoping when adding unit to group

4 posts
#1

Loop stoping when adding unit to group

I am making a simple script that detects which units around a spell target is enemy or friend. But when I add the a command telling to add enemies to another group the loop stops and nothing happens. Why is it so? I saw that there was two commands for adding units to group; "GroupAddUnit" and "GroupAddUnitSimple" is there any difference between those except the argument order?
Any way here is the code:
function Trig_Group_modifications_Actions takes nothing returns nothing
 local unit CV_Caster
 local unit CV_Target
 local unit CV_First
 local location CV_TargetPoint
 local group CV_Group1
 local group CV_Group2
 local integer CV_Limit1
 local integer CV_Limit2
 local player CV_Player
 set CV_Caster = GetSpellAbilityUnit()
 set CV_Target = GetSpellTargetUnit()
 set CV_TargetPoint = GetUnitLoc(CV_Target)
 set CV_Group1 = GetUnitsInRangeOfLocAll(500, CV_TargetPoint)
 set CV_First = FirstOfGroup(CV_Group1)
 set CV_Limit1 = CountUnitsInGroup(CV_Group1) 
 set CV_Player = GetOwningPlayer(CV_Caster)

 call DisplayTimedTextToForce(GetPlayersAll(), 2, "Group trigger detected")
 call DisplayTimedTextToForce(GetPlayersAll(), 2, "Amount in Group1: " + I2S(CV_Limit1))
 call DisplayTimedTextToForce(GetPlayersAll(), 3, "Unit hostility testing in 3 sec.") 
 call TriggerSleepAction(3)
 
 loop 
 exitwhen (CV_Limit1 == 0)
  set CV_First = FirstOfGroup(CV_Group1)
  if (IsUnitEnemy(CV_First, CV_Player)) then 
   call DisplayTimedTextToForce(GetPlayersAll(), 2, "Enemy found in group1.")
   call CreateTextTagUnitBJ("Enemy", CV_First, 100, 10, 100, 0, 0, 0 )
   //call CreateTextTagUnitBJ("Added to group2", CV_First, 200, 10, 0, 0, 100, 0 )   
   //call GroupAddUnit(CV_Group2, CV_First)
  else 
   call CreateTextTagUnitBJ("Friend", CV_First, 100, 10, 0, 100, 0, 0 )
  endif
  call DisplayTimedTextToForce(GetPlayersAll(), 2, "Unit" + I2S(CV_Limit1) + "tested.")
  call CreateTextTagUnitBJ( I2S(CV_Limit1), CV_First, 0, 10, 100, 100, 100, 0 )
  set CV_Limit1 = CV_Limit1 - 1 
  call GroupRemoveUnit(CV_Group1, CV_First)
  call TriggerSleepAction(0.5)
 endloop

 call DisplayTimedTextToForce(GetPlayersAll(), 3, "Unit test complete.")

endfunction
I commented the line which adds unit to the group and stops the loop. And yes I know it leaks I just haven't fixed that yet, just concentrated to get the script working.
#2
You never initialized CV_Group2
#3
So that is the problem. Hmm... I didn't know you had to do this. I thought you just could add a unit to defined a group. Thanks for the help!
#4
It is just a local variable defined, it doesn't point to any group, it doesn't even point to null.

To have a new group use CreateGroup()