(Solved) Play a button click animation only if a variable is "true" or above/under a certain number

Hello, I’ve been trying to get this function to work for 2 hours now. Even though it might sound silly, all I want to do is create a different reaction to a button click depending on whether a variable is greater or smaller than a certain value.

In summary: When the button is clicked and the number of tomatoes is less than 50, a shake animation and a fail sound should play. However, if the number of tomatoes is greater than 50, a different sound and possibly a different animation should play.

I’ve tried everything I could think of, including timers, boolean variables, etc., but nothing has worked correctly. The button always triggers the fail event, even when the number of tomatoes is more than 50 and I click on it. I would appreciate it if someone could help me, as I just started using GDevelop last week and I’m out of ideas to solve this problem.

I apologize if this question has already been answered, but I couldn’t find anything related.

the events should work as intended. Are you sure that your variable was equal to or more than 50 when you have tested the button?

Yes, I am sure. That’s why I am so confused, as I can’t see where the mistake could be.

There is no mistake in your events. I have checked that and it works:

Are you displaying the value of the variable somewhere so that you know for sure?
I would suggest you make a test scene with the events and other actions (instead of playing a sound create an object or tint a sprite) and see if it works for you.

I have reviewed everything again and found the mistake. I have an event that triggers an animation when this button is pressed. The animation costs the player 50 tomatoes, which was causing the variable to be reset to 0 every time something was purchased, thereby preventing another event from being triggered. Thank you for your efforts!

1 Like