# Set Int to switch a specific number of times

**URL:** <https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190>\
**Category:** Platform & Builds\
**Tags:** Switch, logic, unreal-engine, question\
**Created:** [December 13, 2017, 8:01pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190 "2017-12-13T20:01:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donalf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/donalf/32/879767_2.png) [@Donalf](https://forums.unrealengine.com/u/Donalf)\
**Post date:** [December 13, 2017, 8:01pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/1 "2017-12-13T20:01:24Z")

</div>

I’m using Switch 2 and Switch 3 to trigger four things in a row, through a timer.

I want to use Switch 1 to trigger either Switch 2 or 3 but I want it to trigger 4 times in a row, each time.

So I need to get either 0 or 1 randomly, but to count up 4 each time - so that the Switch 2 (connected to pin 0) will trigger 4 times if 0 comes up and Switch 3 (connected to pin 1) will trigger 4 times in a row if 1 comes up.

Any ideas?

 ![223686-int.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/d/4/6d4d78673653be43828d3cd7b0e6c1505d5ab3c1.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 13, 2017, 9:09pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/2 "2017-12-13T21:09:50Z")

</div>

This should work:

 ![223677-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/f/b/4fb3ea5f77dd941e5c922625a9b984765902089d.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8d18c51c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8d18c51c](https://forums.unrealengine.com/u/anonymous_user_8d18c51c)\
**Post date:** [December 13, 2017, 10:16pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/3 "2017-12-13T22:16:02Z")

</div>

Why not just using a branch for switch one?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 13, 2017, 10:32pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/4 "2017-12-13T22:32:37Z")

</div>

You can. You’d still need to roll the dice somehow, though. There’s like 10 ways of doing this, anyway. Was sticking to what OP had already. Not sure what is planned for this further down the line.

Besides, I feel this node is underused so I mention it every time I have a chance ;p

---

<div class="post-metadata">

**Author:** ![Donalf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/donalf/32/879767_2.png) [@Donalf](https://forums.unrealengine.com/u/Donalf)\
**Post date:** [December 13, 2017, 11:04pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/5 "2017-12-13T23:04:45Z")

</div>

If I use the random bool it’ll go randomly between Switch 2 and 3 - I need to get it so if it goes to Switch 2 first it’ll trigger four times in a row, or if it goes to 3 it’ll trigger four times in a row.

The four wires going into the first sequence trigger one after another through a timer - I need to get the first switch to go either 0 four times or 1 four times in a row - or some other way that I can randomly go between Switch 2 and Switch 3, but always firing four times in a row - so that modules of a semi random music system will play in sync.

The four audio components on the left need to synchronise with four audio components on the right, but there are two possible sequences that can occur.

 ![223715-int.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/7/3/b73715915f979f5d57a261caf1b2633db62890df.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 14, 2017, 8:19am UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/6 "2017-12-14T08:19:59Z")

</div>

> I need to get it so if it goes to  
> Switch 2 first it’ll trigger four  
> times in a row, or if it goes to 3  
> it’ll trigger four times in a row.

This is precisely what the code I posted does… Did you test it? When an impulse is sent to _switch #1_ and pin 0 is selected, the script will iterate through a loop once - the loop is 4 elements long so it will trigger _switch #2_ 4 times in a row. The switch will pull the _Index2_ from the _4Array0_ and fire _one_ of its pins 4 times.

Did you want to fire the _switch’s #2_ and _#3_ pins consecutively instead?

By the way, your random integer is set incorrectly, it starts at 0. Now you have a 33.3% chance to trigger 0,1 or Default at _switch #1_

---

<div class="post-metadata">

**Author:** ![Donalf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/donalf/32/879767_2.png) [@Donalf](https://forums.unrealengine.com/u/Donalf)\
**Post date:** [December 14, 2017, 1:42pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/7 "2017-12-14T13:42:34Z")

</div>

Sorry Everynone, I should have been more clear. Because the impulses from the audio components are on a timer, they send in 2 second intervals - so the impulses received by either _switch #1_ or _switch #2_ are arriving one after another, not at the same time, meaning the bool randomises with each impulse. I’m trying to get it so that if it goes to _switch #1_ first it will fire four times in a row, along with the two second timer or if it goes to _switch #2_ it will fire four times in a row.

I’ve made a video to clear it up

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/5/e/85ede7a8e362fa7dfdb2a8205caf7ece39c259a7.jpeg "Audio Sync") ](https://www.youtube.com/watch?v=Eci0BjTN8w8)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 14, 2017, 3:48pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/8 "2017-12-14T15:48:15Z")

</div>

In that case, generate the random for #1 earlier, store it in a variable and use it 4 times. And only re-generate the random when necessary.

---

<div class="post-metadata">

**Author:** ![Donalf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/donalf/32/879767_2.png) [@Donalf](https://forums.unrealengine.com/u/Donalf)\
**Post date:** [December 14, 2017, 5:23pm UTC](https://forums.unrealengine.com/t/set-int-to-switch-a-specific-number-of-times/412190/9 "2017-12-14T17:23:44Z")

</div>

That’s what I’m trying but can’t figure out the BP needed!
