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

Need help with units groups

Status
Not open for further replies.
Level 20
Joined
Feb 23, 2015
Messages
243
Hello

I've made trigger that spawns unit waves for one player and orders them to attack enemy base. Problem is that first two waves work correctly, but third and others only spawn and do nothing. Here are triggers:
  • WaveSpawn
    • Events
      • Time - WaveTimer expires
    • Conditions
    • Actions
      • Unit - Create 1 Ghoul for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Ghoul for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Ghoul for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Ghoul for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Ghul for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Necromancer for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Necromancer for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Crypt Fiend for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Crypt Fiend for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Crypt Fiend for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Meat Wagon for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit - Create 1 Meat Wagon for Player 7 (Green) at (Center of UNSpawnLeftWave <gen>) facing Default building facing degrees
      • Unit Group - Add (Last created unit) to WaveUNLeft[WaveCounter]
      • Unit Group - Order WaveUNLeft[WaveCounter] to Attack-Move (Center of NerubianBaseLeft <gen>)
      • Set WaveCounter = (WaveCounter + 1)
      • Countdown Timer - Start WaveTimer as a One-shot timer that will expire in 60.00 seconds
I use unit groups because there are multiple waves that attack different targets at one time. I also noticed that one crypt fiend from first wave always comes back to spawnpoint.

I would be grateful for help :D
 
Level 9
Joined
Apr 23, 2011
Messages
527
ew, so many leaks :D

there are no problems with the trigger itself, i think. the bug could be caused by another trigger, anyway here, have an optimized version of your trigger:
  • WaveSpawn
    • Events
      • Time - WaveTimer expires
    • Conditions
    • Actions
      • Set loc = (Center of UNSpawnLeftWave <gen>)
      • Unit - Create 5 Ghoul for Player 7 (Green) at loc facing Default building facing degrees
      • Unit - Create 2 Necromancer for Player 7 (Green) at loc facing Default building facing degrees
      • Unit - Create 3 Crypt Fiend for Player 7 (Green) at loc facing Default building facing degrees
      • Unit - Create 2 Meat Wagon for Player 7 (Green) at loc facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_loc)
      • Set loc = (Center of NerubianBaseLeft <gen>)
      • Set WaveUNLeft[WaveCounter] = (Units in UNSpawnLeftWave <gen>)
      • Unit Group - Order WaveUNLeft[WaveCounter] to Attack-Move loc
      • Custom script: call RemoveLocation(udg_loc)
      • Set WaveCounter = (WaveCounter + 1)
      • Countdown Timer - Start WaveTimer as a One-shot timer that will expire in 60.00 seconds
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
Problem is that first two waves work correctly, but third and others only spawn and do nothing.
You are adding them to "null". GUI arrays only create groups for indices up to the size value you provided. After that index it is null and you need to manually create the groups.

The following JASS script can be used to fix this. Insert it line by line in custom script at the top of your trigger before adding units to the group.

JASS:
if udg_WaveUNLeft[udg_WaveCounter] == null then
    set udg_WaveUNLeft[udg_WaveCounter] = CreateGroup()
endif
This will only work if handle array index values are defaulted to "null". I think they are but am not 100% sure.

The solution posted by Light solves this by placing a new unit group in the array each time. He does leak a few groups as a result for the first few array index as they already exist.

Both your solutions suffer from possible spawning performance problems as a result of placing units on top of each other. You should avoid spawning units on top of other units as the displacer used is quite an expensive operation and can easily cause frames to be dropped. I recommend spawning the units randomly in a largely open area since this minimizes the chance the displacer will be used.
 
Status
Not open for further replies.
Top