• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Limited reinforcement waves

Level 23
Joined
Nov 20, 2005
Messages
1,259
Hello. I have a problem with triggers in the map I'm creating, where you lead an army of mixed units, and a scoreboard displays how many remaining additional waves you have before Game Over, sort of acting like a "Player Life" counter on screen.
  • When you have 6 remaining units, a new wave spawns at the starting point of the map.
  • When you destroy gates to advance into the next sector, 2 additional waves are added to the HUD scoreboard and the variable that stores the number of available waves.
  • When you reach 1 waves, that's the last reinforcement wave you get, before it turns to 0, then when all units get killed it's Game Over.

Now, what's the problem? I get only 1 additional wave, but by the time that new wave dies, it's game over.
Anyone can help me to build an accurate working system for this, please?
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
To track waves remaining, use an integer global variable (which are just regular variables in GUI). If your map is multiplayer and you want this mechanic to apply to many players, then turn that integer global variable into an array where the array index is the player slot, mapping player slot number to their units remaining.

  • At map initialisation you set the integer variable to the number of additional waves the players should start with.
  • Another trigger adds 2 to the integer variable in response to the gates being destroyed. If this is a team game you might need to loop through all relevant, allied, players and add 2 to the integer for them.
  • An on unit death trigger counts how many appropriate units a player has remaining. When units remaining is less than or equal to 6 and the integer variable is greater than 0 run your reinforcement wave logic which spawns the new units and reduces the integer variable by 1. If units remaining is 0, run your defeat logic. Be aware that counting units typically involves unit groups which are prone to resource leaks, I strongly recommend you read up about this and add the appropriate clean up code to prevent such leaks.
 
Level 23
Joined
Nov 20, 2005
Messages
1,259
At map initialisation you set the integer variable to the number of additional waves the players should start with.
First off, thank you so much for the help! 🙏
This is the only step that I seemingly haven't accurately done: setting the integer variable to the number of additional waves the players should start with.
I did it out of map initialisation.
Everything else has been set exactly as you explained. The matter about the units counting which involves resource leaks is something that I need to address as well.
Also, it looks like whenever I want to increase or decrease the waves variable, it increases/decreases by 2 instead of 1. I still haven't understood why. There appear to be no more than 1 trigger to handle that function.
I just tested the map and it successfully gave me reinforcement 2 times, before I managed to complete it.
It's a campaign map, so it doesn't involve teams or other human players.
 
Would you be able to share your triggers? It sounds like you're on the right track, but the trigger may be running multiple times. But it is hard for us to tell without knowing the code.

Otherwise we could come up with a sample map that you could use, if that helps to compare your code against.
 
Level 23
Joined
Nov 20, 2005
Messages
1,259
Would you be able to share your triggers? It sounds like you're on the right track, but the trigger may be running multiple times. But it is hard for us to tell without knowing the code.

Otherwise we could come up with a sample map that you could use, if that helps to compare your code against.
Yes, I agree. I'm gonna do this tomorrow; I'm in serious hurry of going to sleep now! 😅🥱
 
Level 23
Joined
Nov 20, 2005
Messages
1,259
Would you be able to share your triggers? It sounds like you're on the right track, but the trigger may be running multiple times. But it is hard for us to tell without knowing the code.

Otherwise we could come up with a sample map that you could use, if that helps to compare your code against.
As suggested from @Dr Super Good , I've reset the value of OrcAvailableWaves to 0, and set it via trigger in the map initialization.
It was initially set to 4, directly through the variables tab, but for some reason the value would display as 5 in the leaderboard.

screenshot-2025-06-08-121741-png.536606


This is the trigger👇 that detects when the current wave you command drops to/under 6 elements.

screenshot-2025-06-08-121847-png.536607


This is the trigger👇 that activates when all units in the current wave are dead, and therefore when waves are down to 0 (otherwise the "6 remaining elements" threshold would trigger instead).

screenshot-2025-06-08-115027-png.536605


I've double-checked and there are no additional triggers that raise the amount of OrcAvailableWaves together with the ones whenever a gate is destroyed. Once again, this value seems to increase by 2 instead of 1.

I haven't tested the map with the updated function in the Map Initialization. I shall give it another go later and report.
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
You can use actions that display messages to help debug triggers. For example you can print one every time the decrement action runs, and print values such as number of units in the wave.

Although really poor compared to more professional debuggers such as in StarCraft II, it still is good enough to give some insight into the order and values of logic being run.
 
Could you also show the trigger you use to spawn units? Ideally it would run after you decrement OrcAvailableWaves. You'll want to make sure you add those units to the group "OrcCurrentWave". In addition, when a unit dies, you'll want to remove them from that unit group--or else they'll remain in the group even when they're dead.

I whipped up a quick sample that follows a more event-based approach, similar to the method that Dr Super Good mentioned. Timers work fine too, but timers can sometimes lead to subtle bugs when you have multiple triggers running simultaneously. For example, in your case, it is possible that the "Defeat Units Dead" timer ticked and detected that all the units in the group were dead before "Wave depleted lower waves counter" ticked to grant a wave. (you could fix that by enabling the "OrcAvailableWaves Equal to 0" condition again, but I still recommend using the direct death events where possible)

I've attached the map below (requires patch v.2.0.2+ to open). If you don't mod on that patch, I'll post the sample triggers below:
  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- --------
      • -------- Grant 3 initial waves --------
      • -------- --------
      • Set VariableSet RemainingWaves = 3
      • -------- --------
      • -------- Spawn an initial wave of orcs --------
      • -------- --------
      • Set VariableSet SW_InputPlayer = Player 4 (Purple)
      • Set VariableSet SW_InputSpawnRegion = WaveSpawnRegion <gen>
      • Trigger - Run SpawnWave <gen> (ignoring conditions)

  • SpawnWave
    • Events
    • Conditions
    • Actions
      • -------- --------
      • -------- Spawn 3 grunts --------
      • -------- --------
      • For each (Integer SW_LoopInteger) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set VariableSet SW_TempLoc = (Random point in SW_InputSpawnRegion)
          • Unit - Create 1 Grunt for SW_InputPlayer at SW_TempLoc facing Default building facing degrees
          • Unit Group - Add (Last created unit) to OrcCurrentWave
          • Custom script: call RemoveLocation(udg_SW_TempLoc)
      • -------- --------
      • -------- Spawn 3 shaman --------
      • -------- --------
      • For each (Integer SW_LoopInteger) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set VariableSet SW_TempLoc = (Random point in SW_InputSpawnRegion)
          • Unit - Create 1 Shaman for SW_InputPlayer at SW_TempLoc facing Default building facing degrees
          • Unit Group - Add (Last created unit) to OrcCurrentWave
          • Custom script: call RemoveLocation(udg_SW_TempLoc)
      • -------- --------
      • -------- Spawn 1 tauren --------
      • -------- --------
      • Set VariableSet SW_TempLoc = (Random point in SW_InputSpawnRegion)
      • Unit - Create 1 Tauren for SW_InputPlayer at SW_TempLoc facing Default building facing degrees
      • Unit Group - Add (Last created unit) to OrcCurrentWave
      • Custom script: call RemoveLocation(udg_SW_TempLoc)

  • OrcDies
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in OrcCurrentWave.) Equal to True
    • Actions
      • -------- --------
      • -------- Remove this unit from the group so it no longer counts towards the total --------
      • -------- --------
      • Unit Group - Remove (Triggering unit) from OrcCurrentWave.
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in OrcCurrentWave) Less than or equal to 6
        • Then - Actions
          • -------- --------
          • -------- If there are more than 0 remaining waves, spawn a new wave --------
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RemainingWaves Greater than 0
            • Then - Actions
              • Set VariableSet RemainingWaves = (RemainingWaves - 1)
              • Set VariableSet SW_InputPlayer = Player 4 (Purple)
              • Set VariableSet SW_InputSpawnRegion = WaveSpawnRegion <gen>
              • Trigger - Run SpawnWave <gen> (ignoring conditions)
              • Trigger - Run RefreshWaveLeaderboard <gen> (ignoring conditions)
              • Game - Display to (All players) the text: Spawned a new wave ...
              • Sound - Play Warning <gen>
            • Else - Actions
              • -------- --------
              • -------- If there are no more waves, check if all units are dead --------
              • -------- If all units are dead, then trigger defeat --------
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in OrcCurrentWave) Equal to 0
                • Then - Actions
                  • Game - Defeat Player 4 (Purple) with the message: Defeat!
                • Else - Actions
        • Else - Actions

  • GateDies
    • Events
      • Destructible - City Entrance 0213 <gen> dies
      • Destructible - City Entrance 0382 <gen> dies
      • Destructible - City Entrance 0460 <gen> dies
    • Conditions
    • Actions
      • Sound - Play GoodJob <gen>
      • Game - Display to (All players) the text: Granted 2 waves for...
      • Set VariableSet RemainingWaves = (RemainingWaves + 2)
      • Trigger - Run RefreshWaveLeaderboard <gen> (ignoring conditions)

  • InitializeLeaderboard
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for (All players) titled Remaining Waves
      • Set VariableSet WaveLeaderboard = (Last created leaderboard)
      • Leaderboard - Change the display style for WaveLeaderboard to Show the title, Show labels, Show values, and Hide icons
      • Leaderboard - Add Player 4 (Purple) to WaveLeaderboard with label (Name of Player 4 (Purple)) and value RemainingWaves
      • Leaderboard - Show WaveLeaderboard
  • RefreshWaveLeaderboard
    • Events
    • Conditions
    • Actions
      • Leaderboard - Change the value for Player 4 (Purple) in WaveLeaderboard to RemainingWaves

At a high-level, when a unit dies in the "OrcCurrentWave", remove it from the unit group. If there are 6 or fewer units remaining after that, then try to spawn a wave if possible--otherwise we just need to check when the number of units drops to 0 to trigger defeat.

Other than that, it is mostly just leaderboard updates. It is quite similar to what you already have--but the event-based approach makes it more reliable and simpler overall. Let me know if you have any questions!
 

Attachments

  • WaveSample.w3m
    29.2 KB · Views: 4
Level 23
Joined
Nov 20, 2005
Messages
1,259
Just passing by to drop this: How To Post Your Trigger
So you don't need to screenshot your code. You can just copy the entire trigger and post it here for others.
Maybe people can help you solve the problem with the full code.
Is there a way to post entire triggers in one go, instead of having to copy every single line? It doesn't seem to clarify it in that tutorial.
 
Is there a way to post entire triggers in one go, instead of having to copy every single line? It doesn't seem to clarify it in that tutorial.
You can right-click the trigger's name and select "Copy as Text". Then it will copy the whole trigger:
1749506108016.png

Similarly, you can right-click any individual section if you just want to copy that portion as text (e.g. actions, events, etc.).
 
Level 23
Joined
Nov 20, 2005
Messages
1,259
You can right-click the trigger's name and select "Copy as Text". Then it will copy the whole trigger:
View attachment 537199
Similarly, you can right-click any individual section if you just want to copy that portion as text (e.g. actions, events, etc.).
THAT'S what I was looking for! Thanks! :D So...
Thanks @PurgeandFire . Before I'll implement your suggestion in the map, I shall paste my own triggers in full. Don't kill me; I've never created such custom maps, because having worked over a plain remake of a game from 1995 didn't imply creating units and massive attack waves in such a fashion.

This is the current Map Initialization trigger, modified with the variable setting, moved from another trigger.

  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Sound - Stop the currently playing music theme
      • Sound - Stop music Immediately
      • Trigger - Run Init 04 Environment <gen> (checking conditions)
      • Trigger - Run Init 01 Players <gen> (checking conditions)
      • Trigger - Run Init 05 Quests <gen> (checking conditions)
      • Set OrcAvailableWaves = 2
      • -------- Start Intro Cinematic --------
      • Trigger - Add Intro Cinematic Q 1 <gen> to the trigger queue (Checking conditions)
This is the trigger👇 that creates the leaderboard.

  • Leaderboard Create
    • Events
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for Player Group - Player 4 (Purple) titled Reinforcements
      • Set OrcsLeaderboard = (Last created leaderboard)
      • Leaderboard - Show (Last created leaderboard)
      • Leaderboard - Add Player 4 (Purple) to OrcsLeaderboard with label Waves and value 2
      • Leaderboard - Change the label for Player 4 (Purple) in OrcsLeaderboard to Remaining waves
      • Leaderboard - Change the color of the label for Player 4 (Purple) in OrcsLeaderboard to (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • Leaderboard - Change the color of the value for Player 4 (Purple) in OrcsLeaderboard to (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • Leaderboard - Show (Leaderboard of Player 4 (Purple))
These 2 actions👇 are listed at the bottom of cinematic triggers that activate once a gate along the path is destroyed.
Once again, the map has a fixed path. Is like a hack & slash where you lead waves of orcs through enemy villages, one by one, and travel across "sectors" separated by these gates that you need to destroy in order to progress.

  • Leaderboard - Change the value for Player 4 (Purple) in OrcsLeaderboard to (OrcAvailableWaves + 1)
  • Set OrcAvailableWaves = (OrcAvailableWaves + 1)
So far, the functions raise the variables from an initial 2 to a resulting 5.

This is the trigger👇 that detects when the current wave you command drops to/under 6 elements.
The single location per unit is created so that the wave spawns in a perfect, pre-set formation.

  • Wave depleted lower waves counter
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
      • (Number of units in OrcCurrentWave) Less than or equal to 6
      • OrcAvailableWaves Greater than 0
    • Actions
      • Cinematic - Ping minimap for (All players) at (Center of Pick btg <gen>) for 2.00 seconds
      • Set OrcAvailableWaves = (OrcAvailableWaves - 1)
      • Leaderboard - Change the value for Player 4 (Purple) in OrcsLeaderboard to (OrcAvailableWaves - 1)
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 11 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 11 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy Copy 7 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 2 Copy 7 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 3 Copy 7 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 4 Copy 7 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 10 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy Copy 6 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 2 Copy 6 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 3 Copy 6 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 4 Copy 6 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 4 Copy 6 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 9 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy Copy 5 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 2 Copy 5 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 3 Copy 5 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 4 Copy 5 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 4 Copy 5 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 8 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 8 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy Copy 4 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 2 Copy 4 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 3 Copy 4 <gen>) facing 124.70 degrees
      • Unit - Create 1 Grunt BHol for Player 3 (Teal) at (Center of Region 000 Copy 4 Copy 4 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 6 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy Copy 2 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 2 Copy 2 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 3 Copy 2 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy 2 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 7 Copy 2 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 7 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 7 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy Copy 3 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 2 Copy 3 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 3 Copy 3 <gen>) facing 124.70 degrees
      • Unit - Create 1 Ogre Black TG for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy 3 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 5 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 2 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 3 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 12 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy Copy 8 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 2 Copy 8 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 3 Copy 8 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy 8 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy 8 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy Copy 2 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 2 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 3 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 4 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy 8 Copy 2 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 13 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy Copy 9 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 2 Copy 9 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 3 Copy 9 <gen>) facing 124.70 degrees
      • Unit - Create 1 Spearthrower for Player 4 (Purple) at (Center of Region 000 Copy 4 Copy 9 <gen>) facing 124.70 degrees
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • okGEMBU Equal to True
        • Then - Actions
          • Unit - Create 1 Genbu for Player 4 (Purple) at (Center of Genbu backup 1 <gen>) facing (Center of attack orange <gen>)
          • Unit - Create 1 Genbu for Player 4 (Purple) at (Center of Genbu backup 2 <gen>) facing (Center of attack orange Copy <gen>)
        • Else - Actions
          • Do nothing
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • okHATRED Equal to True
        • Then - Actions
          • Unit - Create 1 Hatred for Player 6 (Orange) at (Center of Hatred backup 1 <gen>) facing (Center of BB assault after gate crash <gen>)
          • Unit - Create 1 Hatred for Player 6 (Orange) at (Center of Hatred backup 2 <gen>) facing (Center of BB assault after gate crash <gen>)
        • Else - Actions
          • Do nothing
      • Wait 0.25 seconds
      • Unit Group - Pick every unit in (Units in Pick btg <gen> owned by Player 3 (Teal)) and do (Unit - Change ownership of (Picked unit) to Player 4 (Purple) and Retain color)
      • Unit Group - Pick every unit in (Units in Pick btg <gen> owned by Player 6 (Orange)) and do (Unit - Change ownership of (Picked unit) to Player 4 (Purple) and Retain color)
      • Unit Group - Pick every unit in (Units in Pick btg <gen> owned by Player 12 (Brown)) and do (Unit - Change ownership of (Picked unit) to Player 4 (Purple) and Retain color)
      • Wait 0.25 seconds
      • Unit Group - Pick every unit in (Units in Pick btg <gen>) and do (Unit Group - Add (Picked unit) to OrcCurrentWave)
This is the trigger👇 that activates when all units in the current wave are dead, and therefore when waves are down to 0 (otherwise the "6 remaining elements" threshold would trigger instead).

  • Defeat Units Dead
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
      • (All units of OrcCurrentWave are dead) Equal to True
      • GameOver Equal to False
    • Actions
      • Trigger - Turn off (This trigger)
      • Set GameOver = True
      • Wait 2.00 seconds
      • Trigger - Run Mission Failed BaseDead <gen> (checking conditions)
      • Wait Campaign quest delay seconds
      • Game - Defeat Player 4 (Purple) with the message: game over
At the current state of the map, every destroyed gate increases waves of 2, instead of 1, and every wave decreases the count by 2 instead of 1. Detection of the 6 units' threshold happens with a large delay. Last test I did it triggered when I had 5 units remaining.
 
@LordPerenolde II ahh gotcha, thanks for sharing the triggers! And no sweat, we all gotta start somewhere!

After reviewing your triggers, I saw a sneaky lil line that might explain the bugs you're seeing:
  • Set OrcAvailableWaves = (OrcAvailableWaves - 1)
  • Leaderboard - Change the value for Player 4 (Purple) in OrcsLeaderboard to (OrcAvailableWaves - 1)
For example, let's say OrcAvailableWaves is 3, and then the depletion trigger runs. It'll first decrement OrcAvailableWaves, so now it is 2. But since OrcAvailableWaves is now 2, the next line will update the leaderboard to show (2 - 1) which is 1.

This probably causes a lot of confusion, because the leaderboard is showing one thing (1)--but internally variable is actually (correctly) "2". Try fixing that and testing it again!
  • Set OrcAvailableWaves = (OrcAvailableWaves - 1)
  • Leaderboard - Change the value for Player 4 (Purple) in OrcsLeaderboard to OrcAvailableWaves
That's how I'd fix it^. Usually, when you see yourself doing arithmetic in multiple places, it might be a good idea to consolidate the arithmetic in one area if possible to avoid these tricky bugs. :thumbs_up:

Another example would be your incrementing--even though that one doesn't have this bug, it might be good to reverse the order just to keep things simple and consistent!
  • -------- --------
  • -------- This is what your code currently is --------
  • -------- --------
  • Leaderboard - Change the value for Player 4 (Purple) in OrcsLeaderboard to (OrcAvailableWaves + 1)
  • Set OrcAvailableWaves = (OrcAvailableWaves + 1)
  • -------- --------
  • -------- This is what I would recommend --------
  • -------- --------
  • Set OrcAvailableWaves = (OrcAvailableWaves + 1)
  • Leaderboard - Change the value for Player 4 (Purple) in OrcsLeaderboard to OrcAvailableWaves
That'll be a good practice--this way you're always just updating your "state" (e.g. OrcAvailableWaves) in one place and then your views (e.g. the leaderboard) are simply displaying that state directly as-is.



Hopefully that fixes some of your problems! But as an aside, I do still recommend trying it out with the "A unit dies" event to try to avoid the delays you're describing (and any potential other bugs).

And you might want to take a look at this tutorial on memory leaks: Memory Leaks

It doesn't affect the "functionality" of your code, but long-term--it'll be useful to read it up to fix the "point" leaks in that trigger. Basically, any time you use a "point" (e.g. Center of region, position of unit, etc.), it creates an object in memory that needs to be manually removed. Typically, you'll just have one or two variables for that, e.g. TempLoc, and then you can use them and remove them right after you finish your function call:
  • Set TempLoc = (Center of Region 000 Copy 11 Copy <gen>)
  • Unit - Create 1 Grunt BHol for Player 3 (Teal) at TempLoc facing 124.70 degrees
  • Custom script: call RemoveLocation(udg_TempLoc)
It might look a bit complicated at first, but it is pretty easy once you do it once or twice. Then it just becomes second-nature. :)

Good luck! Feel free to ask if you run into any more problems.
 

Rheiko

Spell Reviewer
Level 27
Joined
Aug 27, 2013
Messages
4,247
Is there a way to post entire triggers in one go, instead of having to copy every single line? It doesn't seem to clarify it in that tutorial.
It actually shows you how to post the entire trigger in one go, but I will update that tutorial for a bit. Thanks.
I hope it did help you. ;)
 
Level 23
Joined
Nov 20, 2005
Messages
1,259
After reviewing your triggers, I saw a sneaky lil line that might explain the bugs you're seeing:
  • set.gif
    Set OrcAvailableWaves = (OrcAvailableWaves - 1)
  • lead.gif
    Leaderboard - Change the value for Player 4 (Purple) in OrcsLeaderboard to (OrcAvailableWaves - 1)
For example, let's say OrcAvailableWaves is 3, and then the depletion trigger runs. It'll first decrement OrcAvailableWaves, so now it is 2. But since OrcAvailableWaves is now 2, the next line will update the leaderboard to show (2 - 1) which is 1.

This probably causes a lot of confusion, because the leaderboard is showing one thing (1)--but internally variable is actually (correctly) "2". Try fixing that and testing it again!
  • set.gif
    Set OrcAvailableWaves = (OrcAvailableWaves - 1)
  • lead.gif
    Leaderboard - Change the value for Player 4 (Purple) in OrcsLeaderboard to OrcAvailableWaves
That's how I'd fix it^. Usually, when you see yourself doing arithmetic in multiple places, it might be a good idea to consolidate the arithmetic in one area if possible to avoid these tricky bugs. :thumbs_up:

Another example would be your incrementing--even though that one doesn't have this bug, it might be good to reverse the order just to keep things simple and consistent!
🤦‍♂️I usually have eyes to spot oversights such as this, but how come I haven't noticed this silly one? smh Thank you! 😅

It doesn't affect the "functionality" of your code, but long-term--it'll be useful to read it up to fix the "point" leaks in that trigger. Basically, any time you use a "point" (e.g. Center of region, position of unit, etc.), it creates an object in memory that needs to be manually removed. Typically, you'll just have one or two variables for that, e.g. TempLoc, and then you can use them and remove them right after you finish your function call:
  • set.gif
    Set TempLoc = (Center of Region 000 Copy 11 Copy <gen>)
  • unit.gif
    Unit - Create 1 Grunt BHol for Player 3 (Teal) at TempLoc facing 124.70 degrees
  • page.gif
    Custom script: call RemoveLocation(udg_TempLoc)
So, you say that in that trigger with all of those spawning units for the reinforcement wave, I need to apply temploc to each location and then destroy it right after?

It might look a bit complicated at first, but it is pretty easy once you do it once or twice. Then it just becomes second-nature. :)
Heh... it becomes second-nature, but it's gonna take ages to fix now. 😅 Fortunately I've only done that with a few maps so far. Hopefully it won't take long.

I'll let you know if I run into more issues. :) Thank you again for your precious help!
 
Top