# Switch on int stops working after multiple increments

**URL:** <https://forums.unrealengine.com/t/switch-on-int-stops-working-after-multiple-increments/366738>\
**Category:** Modding\
**Tags:** unreal-engine, question\
**Created:** [August 10, 2016, 4:53pm UTC](https://forums.unrealengine.com/t/switch-on-int-stops-working-after-multiple-increments/366738 "2016-08-10T16:53:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7ba8e7d31](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7ba8e7d31](https://forums.unrealengine.com/u/anonymous_user_7ba8e7d31)\
**Post date:** [August 10, 2016, 4:53pm UTC](https://forums.unrealengine.com/t/switch-on-int-stops-working-after-multiple-increments/366738/1 "2016-08-10T16:53:12Z")

</div>

Hi there,

This is probably an incredibly simple issue to fix, but I can’t seem to find anything about it online. I have a button that increments a switch on int one way and another which increments it the other, however when it cycles through the different switches it stops working. A screenshot of the code is here:  
The only difference between that and the one that increments it the opposite direction is that it subtracts instead of adding.

Edit: Thanks for being so helpful, I’ll look into getting clamping to work when I’m next able to get to my pc.

---

<div class="post-metadata">

**Author:** ![poplockentaco](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@poplockentaco](https://forums.unrealengine.com/u/poplockentaco)\
**Post date:** [August 10, 2016, 5:51pm UTC](https://forums.unrealengine.com/t/switch-on-int-stops-working-after-multiple-increments/366738/2 "2016-08-10T17:51:16Z")

</div>

My guess is that maybe your value for ScreenResolutionSwitch is being set outside the range you have for your switch on int (so outside of 1 through 7), which could happen if you press the button too many times. I’d use a print string to show the value of your ScreenResolutionSwitch on the screen as you press your button. If it’s going outside the range then you know that’s your problem, and you could clamp the values of your ScreenResolutionSwitch to 1 through 7 to fix it. But if you’re not going outside the range then the problem could be somewhere else in your code. If you could post a bit more of what you’re trying to accomplish I might be able to help you find a solution.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7ba8e7d31](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7ba8e7d31](https://forums.unrealengine.com/u/anonymous_user_7ba8e7d31)\
**Post date:** [August 10, 2016, 6:18pm UTC](https://forums.unrealengine.com/t/switch-on-int-stops-working-after-multiple-increments/366738/3 "2016-08-10T18:18:08Z")

</div>

Given what you’ve said, I think that its probably to do with it going outside the range. How would you recommend “clamping” the values? Sorry, I’m a bit of a newbie at this sort of thing.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_67d829db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_67d829db](https://forums.unrealengine.com/u/anonymous_user_67d829db)\
**Post date:** [August 10, 2016, 6:33pm UTC](https://forums.unrealengine.com/t/switch-on-int-stops-working-after-multiple-increments/366738/4 "2016-08-10T18:33:25Z")

</div>

Clamping would work: [https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/Integer/Clamp\_int/index.html](https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/Integer/Clamp_int/index.html)

---

<div class="post-metadata">

**Author:** ![poplockentaco](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@poplockentaco](https://forums.unrealengine.com/u/poplockentaco)\
**Post date:** [August 10, 2016, 10:23pm UTC](https://forums.unrealengine.com/t/switch-on-int-stops-working-after-multiple-increments/366738/5 "2016-08-10T22:23:55Z")

</div>

Here’s another method. It’s essentially a clamp. But you can do whatever works for you man. The ResButton adds to your int and the OtherButton subtracts. Hope it helps.

 ![102382-screenshot+(58).jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/2/f/12fb81bf7f2a237ca06aadfd5f4a70b78046bcd5.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b9532c9a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b9532c9a](https://forums.unrealengine.com/u/anonymous_user_b9532c9a)\
**Post date:** [August 11, 2016, 2:56pm UTC](https://forums.unrealengine.com/t/switch-on-int-stops-working-after-multiple-increments/366738/6 "2016-08-11T14:56:46Z")

</div>

Depending on how you want to do it, I would simply use a modulo:

 ![102478-modulo.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/8/e/b8e66c90cd6cc66c968fbaf0b6704b759fc5f5f4.png)

What this does is reset your int back to 0 when it would reach a specific value. In this case, it will cycle from 0-7 then back to 0 on input 1.
