In my game, if the player presses the control buttons repeatedly, it can lead to accidental death. How can I limit the number of times the control buttons can be pressed so that the player cannot intentionally die by spamming the keyboard?
Note!
Creating a timer doesn’t help.
I’d personally just disable the button in the callback event for when the button is pressed, then re-enable it later on when needed.
2 Likes
You can simply prevent the execution by using a variable.
In the most simple case a boolean that is set true or false depending on whether you action should be executed. You just have to reset the variable accordingly (after a few milliseconds or frames).
If this specific to UI, I would probably go with disabling as tibaverus mentioned.