[Solved]Problem when using variables to setup money

Hi there,

I have used a global variable to add money.

Whenever an object is hit, a certain amount will be added to the global variable Money.

The player can use this money to buy upgrades. This is where I face a problem.

Two seperate upgrades cost for example $100 and $200.

When the player has already saved $200 he can buy both upgrades.

When he buys upgrade 2, there is 200 substracted to the global variable. Now the amount on his bank account is 0, but the problem is he can still buy upgrade 1 as well.

I think this is because the global variable already once hit the 200 mark, and this is why he can still buy the $100 upgrade.

The condition I use to check if there is enough money for Upgrade 1 is
Global variable Money is >99

For upgrade 2
Global variable Money is >199

I have tried to change the condition to Text of the global variable is >99, because the amounts are displayed in a text object.

But this doesnt fix the problem.

Does anyone have an idea?

Thanks in advance

Please read this before posting here. We truly try our best to help but we cannot if we can’t see exactly the problem.

Please find below two screenshots

What do you mean by “already once hit the 200”?
If you hit 200 twice that is 400 so if you subtract 200 you have 200 remain and not 0. Are you certain the remaining balance is 0 or you just think it is 0?
It is just a simple math operation
0 is not > 99. So it is very likely not 0 but 200?

The screenshots are a little different than what I described in my post, my bad.
I will be more specific as per the content in the screenshots.

Right now in my developing game, when the player hits an asteroid, he can get a minimum of $250.

With the $250 he is able to buy upgrade 1 (cost $100) and also upgrade 2 (cost $222).

Let’s say he buys upgrade 2. He has $250 and the amount of $222 will be substracted leaving $28 on his account. This all works perfectly fine.

The $28 should not be enough to buy upgrade 1 (costs are $100). However in the game he is still able to buy this upgrade.
I think it is because the global variable already surpassed the 100 earlier, even though the translated amount in the text object reads 28.

This is the problem I am trying to find an answer for.

I don’t see any problem with your events. The button should be clickable only if Money > 99.
So the value of Money must be > 99 even after you purchase upgrade 2.

How many times can you purchase Upgrade 1 when you supposed to have only $28? Only once or as many times as you want?
And how many times when you have $250? only twice or more?

What if you set the value of Money manually at the beginning of the scene. Do not collect any asteroids, what then? Can you still buy more upgrades then you should?

Oh, wait, you set the animation of the button for upgrade 1 to be clickable when you have $250 but when you buy upgrade 2 you don’t reset the button for upgrade 1 and that is why you can click it even though you don’t have the money but the button is clickable. :+1:
So when you buy upgrade 2, you need to reset the button for upgrade 1 too to be not clickable. And then it should set the button back to clickable again if you still have enough money.
And do the same for upgrade 2 also if you can buy upgrade 1 multiple times.

Just add the check for the money in the second action too

But the button is still going to be shown as clickable. Need to reset the animation too and if he do reset the animation, it is not necessary to check the money in the second event too :+1:

1 Like

Thank you!

How couldnt I think of this… thanks alot man. It worked!

1 Like

Solved