• 🏆 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!

[Solved] Killing a unit inside a UnitGroup loop messes up my trigger.

Status
Not open for further replies.
Level 3
Joined
Nov 12, 2018
Messages
43
I want to pick every unt in a group matching some conitions and then deal damage to them. This works fine as long as I don't kill any unit. If I do, then the UnitGroup loop still cycles through all units inside the UnitGroup, but:
1. every other unit after the dead one, doesn't recieve damage any more,
2. the UnitGroup is empty without killing/removing any unit (see log "Unit dies"),
3. functions after that loop aren't executed. (there is other stuff that shoud happen)

What is happening?

  • Set a_HA01_TargetGroup[loop_HumanPlayerA] = (Units within 250.00 of (Position of player_HERO[loop_HumanPlayerA]) matching ((((Matching unit) is A ground unit) Equal to True) and ((((Owner of (Matching unit)) is an enemy of (Owner of player_HERO[loop_HumanPlayerA])) Equal to True) or ((Owner of (Matchin
  • Set a_HA01_Data_InitalDamage = (((Real((Strength of player_HERO[loop_HumanPlayerA] (Include bonuses)))) + (Real((Intelligence of player_HERO[loop_HumanPlayerA] (Include bonuses))))) x a_HA01_Data_DamageFactor[(Level of HA01_Burning Cross for player_HERO[loop_HumanPlayerA])])
  • Set temp_Int = 1
  • Game - Display to (All players) the text: (Unit count before damage = + (String((Number of units in a_HA01_TargetGroup[loop_HumanPlayerA]))))
  • Unit Group - Pick every unit in a_HA01_TargetGroup[loop_HumanPlayerA] and do (Actions)
    • Loop - Actions
      • Set temp_Real = (Life of (Picked unit))
      • Unit - Cause player_HERO[loop_HumanPlayerA] to damage (Picked unit), dealing a_HA01_Data_InitalDamage damage of attack type Spells and damage type Normal
      • Game - Display to (All players) the text: ((String(temp_Int)) + ( damaged: From + (((String(temp_Real)) + HP to ) + ((String((Life of (Picked unit)))) + HP.))))
      • Set temp_Int = (temp_Int + 1)
  • Game - Display to (All players) the text: (Unit count after damage = + (String((Number of units in a_HA01_TargetGroup[loop_HumanPlayerA]))))
  • Unit Group - Remove all units from a_HA01_TargetGroup[loop_HumanPlayerA]

Unit dies:
logzrz.png

Unit survives:
log2fef.png

/edit1:
  • Unit Group - Remove all units from a_HA01_TargetGroup[loop_HumanPlayerA]
This function doesn't work? If I cast my spell a second time - even with no "visible" bug - the UnitGroup isn't empty.
log3mqm.png

/edit2:
  • Set a_HA01_TargetGroup[loop_HumanPlayerA] = (Units within 250.00 of (Position of player_HERO[loop_HumanPlayerA]) matching ((((Matching unit) is A ground unit) Equal to True) and ((((Owner of (Matching unit)) is an enemy of (Owner of player_HERO[loop_HumanPlayerA])) Equal to True) or ((Owner of (Matchin...
This picks corpses! XD
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,021
I can’t read the full matching condition (it gets truncated with a ... if it’s too long when you copy it from the trigger editor) but yes you have to filter out dead units. If groups couldn’t pick dead units how would we ever find/refer to them?

Post the map, I don’t see why this should be happening.
 
Level 3
Joined
Nov 12, 2018
Messages
43
logqcq.png


Im using a local integer "loop_HumanPlayerA" for my loop and set a global variable "udg_loop_HumanPlayer" inside the loop for GUI indexes. I do this in order to prevent interferences between multiple loops that uses the same integer - which I still have. Not all of them are using a local integer yet. I believe, thats why my global Integer becomes "7" if a unit dies.

I'm going to convert every global loop into a local and check, if there are stil any interferences.
Thx for your advice Tasyen.
 
Last edited:
Level 3
Joined
Nov 12, 2018
Messages
43
Group actions, matching Filters and If/Wait-Condtions are not in the same function as Actions. If you set a local at the start of Actions one can not use it inside a group loop. The group is inside the same Trigger.
Yes I noticed. The editor doesn't allow me to use locals inside GUI group actions.

Looks like I have to use unique global integers for EVERY loop.. :confused:
I don't want to create hundreds of them. Does anybody know a better method? Except writing in jass.
 
you can declear local backups then after you are done reset the globals to the values of the local backups. one can also create locals for the group loop block only.
  • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • Custom script: local integer Backup = udg_Int
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Custom script: set udg_Int = Backup
 
Level 3
Joined
Nov 12, 2018
Messages
43
you can declear local backups then after you are done reset the globals to the values of the local backups. one can also create locals for the group loop block only.
  • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
      • Custom script: local integer Backup = udg_Int
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Custom script: set udg_Int = Backup
This is exactly what I need! So elegant. Thank you very much! :D
 
Status
Not open for further replies.
Top