[Solved] Strange issues with variables behaviours

Hi, I’m currently working on my game, and I’ve encountered an issue where the increment and decrement action for one of my numeric variables don’t seem to be functioning correctly. I’m unsure if this is a bug or if there’s something I might be missing. Has anyone else experienced a similar problem or can provide guidance on resolving this issue?I’ve created another game with only two actions to pinpoint the issue. I’ve tried using text variables, boolean variables and numeric variables without incrementing (or decrementing), and everything works fine. It seems to be specific to the increment and decrement actione. Has anyone else encountered a similar problem, or does anyone have insights on what might be causing this issue? I use a mac.

The second game (easy version for find issue)
debug at the start


name variable: variable and value 1

debug after space key (once)

variable = 10 and not 2

Code

thanks
Chiara

Sorry I’ve resolved the issue… after the space key (together) I put trigger once and now work!
Thanks

Hi Chiara,

Glad to hear you resolved the issue. I thought it might be best to explain what is happening here for future reference.

You’re using the X key pressed condition which checks to see if the chosen key is pressed every frame (you can think of a frame as a single instance of the games logic being executed. This is typically ran 30-60 times per second).
This means even if you only held your spacebar for a fraction of a second, the logic had a chance to run multiple times leading to multiple increments!

An alternative to using the “trigger once” in this situation is to instead use the X key released condition that should only ever fire for a single frame.

1 Like