1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Need help with units groups

Discussion in 'Triggers & Scripts' started by MatiS, May 25, 2015.

  1. MatiS

    MatiS

    Joined:
    Feb 23, 2015
    Messages:
    208
    Resources:
    29
    Models:
    27
    Packs:
    2
    Resources:
    29
    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
     
  2. Light

    Light

    Joined:
    Apr 23, 2011
    Messages:
    491
    Resources:
    0
    Resources:
    0
    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: May 25, 2015
  3. MatiS

    MatiS

    Joined:
    Feb 23, 2015
    Messages:
    208
    Resources:
    29
    Models:
    27
    Packs:
    2
    Resources:
    29
    Thanks, waves are attacking correctly now. Some units still come back to the base, but they are not supposed to stay alive long enough to do it :D.
     
  4. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,546
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.

    Code (vJASS):

    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.