Coin collection adding lives problem

I have it set up so that at the beginning of the first Scene, the global variable for Coins is set to zero:

Then, the following is called into each scene via an external event:

The idea is that each time 100 coins are collected, a life is added (global variable “Lives”) and then the coin count is reset to zero.

This works exactly as intended…about 50% of the time. The other 50% of the time the coins just keep counting higher and higher, well over 100. Sometimes an entire game will go by and it performs as expected each time. Sometimes the first 100 coins will result in an extra life, but then after that it just keeps collecting coins. Sometimes it just keeps collecting coin and never adds a life at all.

Any ideas/insight as to what is causing this to work perfectly only half the time?

2 Likes

Hello!
Read this.

http://wiki.compilgames.net/doku.php/gdevelop5/tutorials/basic-game-making-concepts

In addition, you can ensure and write as follows:

i think your msin problem is the =100 check as said above.
Take in mind that you do a loop for each coin add 1 to coins global variable, so if you are lucky you will have exactly 100, bit if you add up to 101 The condition = 100 will never be true
You can use >= 100 and then do coins=variable(coins)-100 so you still retain the coins above 100 if any
I hope my explanation is clear

1 Like

Thank you so much! “<=“ seems to be working. I think maybe if more than one coin was hit at the same time it would get to 101 and not reset. :man_shrugging:t3: Thank you all so much for your help.

1 Like