Why it doesnt't work? (Upgrade button)


When i press the Buy button it does everything from these pics instantly. (Minus 80 gold and max lvl Shield instantly) While i want it to be upgraded gradually every time i click it. If i add Trigger once it doesnt work at all

Hello, guest

Gdevelop “read” the events from top to the bottom. So, when you press the Buy button the first upgrade change the global variable ShieldLevel to 1 making your next event true. The next event put ShieldLevel to 2 making the next true and so on.

I think the most easy way to solve is changing the order of events to descending order:
ShieldLevel = 8
ShieldLevel = 7
ShieldLevel = 6
…

So, when Gdevelop starts and read your condition with ShieldLevel = 0 the condition ShieldLevel = 1 will have already passed.

But why does it execute everything if every event has “Left button released” after the variable checking?

Edit: The sheildLevel check should’ve been 7 not 8. I changed it

I’m not sure what your rules of play are. Do you want each press to upgrade the sheilds by 1 level? Does each upgrade cost10 times the next SheildLevel?

Unless I’m looking at this wrong. Each group seems to do the same thing. If you calculate the cost based on the sheild level then you could do all 8 sheild levels with one group.

Instead of fixed prices multiply the cost per upgrade times the glibal variable ShieldLevel.

At the start of the group
Global Variable SheildLevel ≤ 7

and then lower 
Global variable Money ≥ 10*(GlobalVariable(SheildLevel) +1)

and the action would be
Global Money subtract 10*(GlobalVariable(SheildLevel)+1)
1 Like

As far as your current events. The code created a chain of events like dominos.

The code is processed from top to bottom with events like key released updating in between each pass of your events.

The trigger once only affect each group of events. So, each individual group only triggers once.

In your events, the first group checks for level zero, if there’s enough money it lowers the money and increases the sheild level.

The next group doesn’t care what just happened except for the money variable being reduced.

The sheild level is now 1 So, it goes through all of those conditions and if true it subtracts more money.

This continues until the sheild level is full or the money is insufficient.

Now, if the order was reversed, the first condition would check for level 7 . If there was enough money it would process. The sheild would be 8.

The next group is checking for 6. So, it won’t process any of the actions. The same for all the other events.

2 Likes

Complementing @Keith_1357 explanation:

Gdevelop read all your events from top to bottom every frame. It executes about 60 times per second.
In your game when the player released the left button it will “happen” in 1 frame. So, in that frame what Gdevelop will do? Will read all your events because is that what it does. So for all events that run the check of “Left button released” will be true on that frame.

I tried to explain it in a simple way, but English is not my native language. I hope you managed to understand.

2 Likes

Get it. Your suggestion is much better than mine. Thank you guys for the detailed explanation.

1 Like

We’re all still learning. It takes time.