• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Running multiple loops at once

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
Hi,

I'm working on a map at the minute that is intended to support 4 players each with their own creeps spawning. The thing I want to do is have a loop that runs from 1 to 4, then each say 0.5 seconds it spawns a creep.

In the past this means that it would run all of the 0.5 seconds of the first loop before running onto 2-4. Am I correct in thinking this? Does anyone have any suggestions for making this? I'm hoping I can use various arrays that have a size of 4 to just loop to each player if that's possible...
 
Level 11
Joined
Jun 2, 2004
Messages
849
I'm not sure what the problem is. Are you putting waits inside loops? You shouldn't do that if so.

If you want a trigger that spawns a creep for each player every 0.5 seconds, have a periodic trigger that runs every 0.5 seconds and loops through each player.
 
Level 13
Joined
Oct 16, 2010
Messages
731
Yeah I thought I shouldn't use waits but I'm not really sure how to use timers... Here's my trigger at the minute and it does exactly what I thought it would...

  • Spawning
    • Events
    • Conditions
    • Actions
      • For each (Integer SpawnLoop) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Player_Defeated[SpawnLoop] Equal to False
            • Then - Actions
              • Set SpawnInt[SpawnLoop] = WaveNo
              • For each (Integer Spawn_Array[SpawnLoop]) from 1 to SpawnInt[SpawnLoop], do (Actions)
                • Loop - Actions
                  • Wait 0.50 seconds
                  • Set TempPoint = (Random point in SpawnRegion[SpawnLoop])
                  • Unit - Create 1 Murloc Tiderunner for (Player((SpawnLoop + 8))) at TempPoint facing Default building facing degrees
                  • Unit Group - Add (Last created unit) to EnemiesGroups[SpawnLoop]
                  • Unit - Order (Last created unit) to Attack-Move To Base_Point[SpawnLoop]
                  • Custom script: call RemoveLocation(udg_TempPoint)
            • Else - Actions
 
Level 11
Joined
Jun 2, 2004
Messages
849
Well one easy fix is to move the wait to the very bottom of the trigger (outside the loop), and then after it add the action Trigger - Run Trigger (This Trigger)


Possibly of note, waits bug out if there's lag or if someone pauses the game (it won't pause the wait's timer). Game time waits work better, though I've been told that they leak. Timers are the best but you said you didn't understand them yet.
 
Level 11
Joined
Jun 2, 2004
Messages
849
Oh I see what you're trying to do, looking closer. Your logic's all messed up xD

You already have a variable for determining the wave number, so don't change that. You need another variable to keep track of which unit is being spawned (let's call it SpawnNum). At the end of the trigger before the wait, increment SpawnNum by 1, and wherever you increment WaveNo set SpawnNum back to 0.
  • Spawning
    • Events
    • Conditions
    • Actions
      • For each (Integer SpawnLoop) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Player_Defeated[SpawnLoop] Equal to False
              • SpawnNum less than SpawnInt[SpawnLoop]
            • Then - Actions
              • Set TempPoint = (Random point in SpawnRegion[SpawnLoop])
              • Unit - Create 1 Murloc Tiderunner for (Player((SpawnLoop + 8))) at TempPoint facing Default building facing degrees
              • Unit Group - Add (Last created unit) to EnemiesGroups[SpawnLoop]
              • Unit - Order (Last created unit) to Attack-Move To Base_Point[SpawnLoop]
              • Custom script: call RemoveLocation(udg_TempPoint)
            • Else - Actions
      • Set SpawnNum to (SpawnNum + 1)
      • Wait 0.50 seconds
      • Trigger - Run (This trigger) (ignoring conditions)


As for timers, in this case you can simply not use waits and use the trigger event "Periodic Event" and set it to run every 0.5 seconds.
In other cases you you might need a timer in a variable. In which case, you create a timer variable as normal, and add the event to the relevant trigger "Time - Timer Expires". Then, when appropriate, you start the timer with the action "Countdown Timer - Start Timer".
 
Level 13
Joined
Oct 16, 2010
Messages
731
I think I get your trigger... I was intending to add a part that would only spawn up to say 25 units at a time. So if there were 25 units already in the wave it would wait till some die before spawning more. How would I do this??
 
Level 11
Joined
Jun 2, 2004
Messages
849
Create a unit group array with a size of 4 (one for each player), and add spawned units to them when made. You can then check how many alive units are in the unit group to count how many are currently on the field.
 
Level 9
Joined
May 31, 2004
Messages
90
you cannot have a "wait x.xx seconds" inside a loop integer, it just doesnt work.

If you want like 10 units spawn 1 every 0.5 seconds after each other,
you have to make 1 unit spawn and run the trigger 10 times for that with a wait of 0.5 seconds somewhere in it

you can use an integer that counts to 10 and when it reaches 10 you dont run the trigger again and set it back to 0 for the next wave.
 
Status
Not open for further replies.
Top