Can this work - Collecting pickups?

We have another level that has 10 pickups and when player eat 7 pickups it didn’t say you win until he reach 10 pickups so can this work?

PlayerController.prototype.setCountText = function() {
    this.countText.element.text = 'Count: ' + this.count;
    if (this.count >= 7) {
        this.winText.element.text = 'GG, You win!'
        this.restartText.element.text = 'Go to levels to play the next level'
        won = true;
    } else {
        if (this.count >=10) {
            this.winText.element.text = 'GG, You win!'
            this.restartText.element.text = 'Go to levels to play the next level'
            won = false;
        }
    }

    if (this.count >= 10) {
        this.winText.element.text = 'GG, You win!'
        this.restartText.element.text = 'Go to levels to play the next level'
        won = true;
    } else {
        if (this.count >= 7) {
            this.winText.element.text = 'GG, You win!'
            this.restartText.element.text = 'Go to levels to play the next level'
            won = false;
        }
    }
};

Hi @TheGiantNinja! I don’t really understand your question in combination with the script you share. As far I can see, line 15 and below will never be reached in that script.

Hi @Albertos! we have a level that has 10 pickups but when the player eat 7 pickups it say You win as you see in the script the problem is that we want the win text appear when player eat 10 pickups

If it was my game, I would specify how many pickups there are at start of the level in a variable.

this.levelCount = 10;

Then I would do something like below.

if (this.count >= this.levelCount) {
    // win
}
2 Likes

Alrigth @Albertos i’ll try it, thanks for helping

It didn’t work i’m trying to figure out the problem

@TheGiantNinja I think it may be a good idea to throw a few console.log("") s into your script.

And also insert inside you if statements. Hard to tell what is going on with the variable. It will never evauluate any of your conditions if the count is not increasing. Also, you could condense your code a lot by just evauluating between 7 and 10. So you could use something like

if((this.count >= 7) || (this.count >= 10)) {


} else {

}

seems like the same results are moved to the text element each evaluation. You will not know for sure until you see the console. You can also debug further by putting console.log() s inside your evaluations.

1 Like

Okey Tirk i’ll try it