samedi 2 février 2019

If statement - Boolean used to grow / decrease size of ball

I have an assignment where I try to increase / decrease the size of a ball within certain bounds. I'm trying to use a boolean 'grow' to check if it reaches 30 I'll change it to false and if it reaches 5 I'll change to true. The variable diameter starts at 20 and the boolean as true.

While true - increase diameter, while false decrease.

The function is called every tick so using if statement instead of while as it's called multiple times.

It seems as I reach 30 it runs twice, changes the boolean to false but for some reason it doesn't start decreasing in size.

Any insight please? I'm going nuts here.. feels like it'll be something obvious..

if (diameter == 30){
            grow = false;
        }
        if (diameter == 5){
            grow = true;
        }
        if (grow = true) {
                setballsize(diameter);
            diameter++;
            }
        if (grow = false) {
            setballsize(diameter);
            diameter--;
        }

Aucun commentaire:

Enregistrer un commentaire