# How do I make it so that the program waits until the value is reached

**URL:** <https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [August 6, 2023, 11:06pm UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972 "2023-08-06T23:06:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 6, 2023, 11:06pm UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/1 "2023-08-06T23:06:24Z")

</div>

How can I make it so that once activeOrders = 5, the program waits for activeOrders to become equals to 3?

---

<div class="post-metadata">

**Author:** ![Jeremy\_Choud](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jeremy_choud/32/907645_2.png) [@Jeremy\_Choud](https://forums.unrealengine.com/u/Jeremy_Choud)\
**Post date:** [August 7, 2023, 3:27am UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/2 "2023-08-07T03:27:03Z")

</div>

any code examples you can provide? There are lots of ways to do this.

---

<div class="post-metadata">

**Author:** ![GabUECV](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gabuecv/32/1194717_2.png) [@GabUECV](https://forums.unrealengine.com/u/GabUECV)\
**Post date:** [August 7, 2023, 9:00am UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/3 "2023-08-07T09:00:29Z")

</div>

[I suppose you are using blueprints] You can have a similar behavior than “wait” by using an event dispatcher:

- the code that needs to wait for the value to be reached binds an event to be called to the event dispatcher. This event contains the code that needs to be done after the value is reached.
- the code that update the activeOrders variable simply call the event dispatcher once the value is reached

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 7, 2023, 12:00pm UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/4 "2023-08-07T12:00:55Z")

</div>

Here is the part of the code I’m trying to edit :

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/e/e/8eebbc46b36c0552058a92859c2b54666e8ecb41.png)

---

<div class="post-metadata">

**Author:** ![Jeremy\_Choud](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jeremy_choud/32/907645_2.png) [@Jeremy\_Choud](https://forums.unrealengine.com/u/Jeremy_Choud)\
**Post date:** [August 7, 2023, 9:00pm UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/5 "2023-08-07T21:00:18Z")

</div>

you could set a loop to do nothing until you get the number you want

so like  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/0/c/a0c5e02979e1072a58309fc83c70752169f18562.png)

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 7, 2023, 11:21pm UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/6 "2023-08-07T23:21:36Z")

</div>

Seems to work but when I call the function, I get this error and I believe it has to do with the suspends on the StartAt3 function:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/7/fb767dfe7a6a0434330955d4842cfa43503f1a7c.png)

---

<div class="post-metadata">

**Author:** ![Jeremy\_Choud](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jeremy_choud/32/907645_2.png) [@Jeremy\_Choud](https://forums.unrealengine.com/u/Jeremy_Choud)\
**Post date:** [August 7, 2023, 11:27pm UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/7 "2023-08-07T23:27:50Z")

</div>

you could try spawning the function like this

spawn{StartAt3()}

or add to the function that your calling StartAt3 in

---

<div class="post-metadata">

**Author:** ![nelmi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nelmi/32/746978_2.png) [@nelmi](https://forums.unrealengine.com/u/nelmi)\
**Post date:** [August 7, 2023, 11:29pm UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/8 "2023-08-07T23:29:17Z")

</div>

That works, great! Besides that, could you please explain why it needs to spawn (I’m still learning verse)

---

<div class="post-metadata">

**Author:** ![Jeremy\_Choud](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jeremy_choud/32/907645_2.png) [@Jeremy\_Choud](https://forums.unrealengine.com/u/Jeremy_Choud)\
**Post date:** [August 8, 2023, 2:09am UTC](https://forums.unrealengine.com/t/how-do-i-make-it-so-that-the-program-waits-until-the-value-is-reached/1252972/9 "2023-08-08T02:09:17Z")

</div>

spawning might not be the best option i’d need to see the rest of the code but think of it as running an instance of the function almost.

so if you were iterating over an array of something and you have sleep inside of the function, sleep essentially stops and waits.

So if you were calling a function while iterating over an array of players without spawning it would print fallback function started, then sleep for 15 seconds, then whatever arguments you’ve put in place, then it would move to the next player.

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/5/3/953dbc114937869a2361c77bb0c661462eb7f7a6.png)

When you spawn a function it runs as many times as it’s called at the same time.

(Edit) :

You might not even have to spawn the function if you added suspends to your OnNewOrderTimeFinish Function like :

OnNewOrderTimerFinish(MaybeAgent:?agent):void=
