Wait for condition?

X-maul

AKA: Demtrod
Reaction score
201
I got a "Wait for condition" check ever 1 second.
The condition is that a unit group is empty (no living units)
But I need one of the units to spawn a new unit upon death which is added to the unit group.
So if the last unit in the unit group dies, but with a trigger instantly spawning a new unit, and is added to the unit group - will the wait expire?
 

Dave312

Censored for your safe viewing
Reaction score
269
I would say yes, but I'm not 100% sure. It really depends on whether the "Death" event is called before the "Create Unit" event.

What you might need to do is after the wait expires, add another wait with a duration of 0.1 seconds and then re-check to see if the unit group if empty. If it is, then continue, otherwise loop back to your first wait. Alternatively you could try creating a separate triggers and use unit death events with a wait then a condition to check if the unit group is empty.

On a side note, can you have waits in a custom condition? Because that could also be solution.
 

X-maul

AKA: Demtrod
Reaction score
201
I would say yes, but I'm not 100% sure. It really depends on whether the "Death" event is called before the "Create Unit" event.

What you might need to do is after the wait expires, add another wait with a duration of 0.1 seconds and then re-check to see if the unit group if empty. If it is, then continue, otherwise loop back to your first wait.
Oh, yeah that might be a good idea :) Will try that out :)
On a side note, can you have waits in a custom condition? Because that could also be solution.
Uhm, I'm not sure I understand:rolleyes:
 

Dave312

Censored for your safe viewing
Reaction score
269
Ok I just did some testing and you can have waits in a custom condition.

Rather than trying to create loops in your trigger, you could create a custom condition with a built in recheck:
Trigger:
  • UnitGroupIsEmpty
    • Options: Condition
    • Return Type: Boolean
    • Parameters
      • UnitGroup = (Empty unit group) <Unit Group>
    • Grammar Text: UnitGroupIsEmpty(UnitGroup)
    • Hint Text: (None)
    • Custom Script Code
    • Local Variables
    • Actions
      • General - If (Conditions) then do (Actions) else do (Actions)
        • If
          • (Number of Living units in UnitGroup) == 0
        • Then
          • General - Wait 0.1 Game Time seconds
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • (Number of Living units in UnitGroup) == 0
            • Then
              • General - Return True
            • Else
              • General - Return False
        • Else
          • General - Return False

All you need to do is call this custom Condition in your Wait For Condition action. I'd advise telling it to check greater than 0.1 seconds so you don't have two copies of the condition function running at the same time.
 

X-maul

AKA: Demtrod
Reaction score
201
Oh, have never actually used Custom Conditions before, but it seems to be pretty easy to use. Thank you Dave, it works as a charm now :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top