• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Loop stoping when adding unit to group

Status
Not open for further replies.
Level 12
Joined
Apr 29, 2005
Messages
999
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:
JASS:
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.
 
Status
Not open for further replies.
Top