Creating buttons with animations

I need help, I am doing something wrong here.

The idea is to have a button that will allow to buy upgrades.

The button (object) has separate animations, and once the player has enough money in his money score, a certain animation will be made visible (the animation is a png showing the amount of money).

When the button is clicked/touched, the animation should move forward to a next one, depending on how much money he has (in total it has 14 animations).

I am testing when I already have a lot of money. I want to do the upgrades for the first time.
I click on the button to buy the 22 upgrade, but then the animation goes straight to the very last one, instead of going to the animation showing 34.

I thought it had to do with the cursor/touch sequence, and tried with “trigger once” (everywhere), but it doesnt help.

Please tell me what I am doing wrong.


On the conditions try doing a range. For example test this on the very last conditions… add an extra line

The scene variable is NOT less than 34

then I think it’s going to change the animation to number 4, instead of number 5. If it does, then you just need to specify the range like that in all of the events.

Also I think you need to do Trigger Once on your Left Mouse Down condition, otherwise I think it might subtract 22 on every frame that the mouse is held down

Thanks for your reply, but it doesnt work.

I think because there is plenty of money, when the button is touched for the first time, it goes down and activates the full sequence of all conditions, including writing away all storages placed in the conditions.

I have also tried to set it up with temporary scene variables, but it goes in the same loop.

Have you tried putting a text object in the scene just to display the amount of money when you click? (Just for problem-solving) You can add a line something like

Action: Modify text of YourTextObject set to Variable(MoneyScore)

Then you should be able to see what number it’s hitting when you click

Also just a thought… if you’re writing to storage (and not deleting them?) then wouldn’t the Upgrades already exist in the storage whenever you start the preview…
If they both exist in storage already at the beginning of the preview, it might be skipping to last anim when you click because of that… Just a possibility

I understand what you mean, and because of that I always clear the site data in the preview window before testing. Its a tedious job, but necessary.

About the text object, well I am clicking on the green 22, and it goes straight to the last image. So it should have the same effect?

Do you have the MoneyScore displayed anywhere already? If not, a visual check (with a Text object) for what that variable is doing could help towards solving the issue. Everything depends on that variable. It sounds like it’s not subtracting 22 when you click, but instead it’s going above 44.

The MoneyScore is displayed and it is fully working.

I have an “Upgrade Menu” and I initially had buttons to allow 1 upgrade per button. (3 animations).
It was simple; the animation is greyed out, the money is sufficient so the animation becomes green, then the upgrade is purchased and the animation turns to complete status.

It was working like a charm, until the other day I had the idea to add more upgrades per button.

But with the extra animations, it just doesnt seem to work. I have already spent days trying to figure this out.

Ok, when you click for the first time, what does the MoneyScore text object say (not the button but the text object tied to the variable)

The score before clicking the first time is: 36311
When I click, the score is: 36031
This is without the trigger once condition

When I add the trigger once condition the substraction is indeed 56
So that is correct

But the animation is set to the last one

by the way, thanks for your help so far

I didn’t expect the money score to be that high… So I’m a bit confused…
I think what’s happening is that your conditions are set to just double digit values, which the money score far exceeds so when you click the first time, it runs through the entire script

the number 36031 is far higher than both 21 and 44. So it’s getting there immediately.

To test it I need money, so I collect money (by shooting asteroids :grin:) and I just add alot of money per hit.

By the way, the substraction 56 what I mentioned earlier of course is not correct, but makes more sense when the trigger once condition is added than when the condition is not there.
The first time click should substract 22, but goes further by substracting both 22 and 34.

The problem is that the click on the button also applies for future states of the animation, when it should apply to just one click.

The animation that is displayed is the 45 image. And my understanding was that should not be possible because the added condition is “Upgrade001B exists in storage Score”, which shouldnt be there from the beginning.

Try doing Left Mouse Button Released (instead of Down) and see if it stops at animation 3

If you make all those money score variables larger numbers than the MoneyScore then it shouldn’t go all the way to the end. Try to test it out by adding 5 zeros to the end of all these money score variables… Then I think it’ll stop at animation 1 or anim 4

Button released doesnt change anything.

adding the zero’s sets the animation to 0

Ok I think you put zeros on all the variables (not just the ones in the image I pasted) but either way do you see what the issue is? The variable MoneyScore is a much, much larger number than all the variables you’ve specified there so all of your events are being run through with that first click.

Yes, but in the game, it should be possible.

You can have a large score and then use it to buy upgrades.
I just ran another test with my score set at 500, the problem persists.

This is exactly the problem, and I hope I can find an answer to this problem

The score 500 is still higher than all of the MoneyScore events so the problem would still persist if you tried that. Try setting the score to 32 and buy upgrade. It should stop on animation 2 or 0.

I know that will work, but it is very possible a player wants to save up his money. And then buy upgrades.

Anyway, I might have to look at alternatives to accomplish the same effect

Ok here is the wiki info on variables to understand them a bit better Variables [GDevelop wiki]

and I’d recommend checking some tutorials on Youtube about variables.

Thanks, I’ve tried the variables, but perhaps to achieve what I want is not possible when using multiple animations in one object.

Unless someone has another idea!