Switch on int stops working after multiple increments

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.

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.

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.

Clamping would work: https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/Integer/Clamp_int/index.html

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.

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

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.