How to do a Variable that changes things based on their number automatically

hi guys i’ve been struggling with this for a long time and im not sure if it is possible, the problem is that you have to create “compare the variable” for every value

Problem example: "John is making a game where you have to collect coins to get giant car, so for every 20 on variable “coins” he wants to scale the car by 0.1 but for that code he’s doing this:

coins = 20, car + 0.1 scale
once while true
coins = 40,car + 0.1 scale
once while true
coins = 60, car + 0.1 scale
once while true
coins = 80, car + 0.1 scale
once while true
coins = 100, car + 0.1 scale
once while true
coins = 120, car + 0.1 scale
once while true

the problem is that john’s game is endless and to do that for a endless game he would need thousands of code lines.

All john wants is to add scale to the car procedurally/dynamically/based on the variable coins

I hope this explains it well

thanks

Hi,

for this you could use the modulo expression (in Gdevelop ‘mod’) for checking if your variable (the coins) is evenly divisible by 20. If the remainder is 0 you can increase the scale of your car.

The event could look like:


The condition is: ‘compare two numbers’.

In this example it is a subevent of the coin-car collision just to check for the value if a coin collection happens, but you could put it somewhere else.

2 Likes

thanks you helped me so much :heart:

1 Like