Hi everyone, I’ve been tearing my head out over a gamebreaking bug that set in the moment we moved past Ben’s challenge in this lesson to set up the variable breakableCount (though in my case I named it bricksLeft). I’ve looked over the end state code, and I’ve made small tweaks over the last hour or so to try to correct it, but nothing I have tried seems to fix it.
If I beat the level on the first try, everything works perfectly, no bugs as far as I can tell, when all the breakable bricks on the level are broken the game moves on to the next level or goes to the win screen. But if you fail the level and try again, it seems to keep the bricksLeft at the last frame of your previous attempt and add it to the new bricksLeft. So if you have 3 bricks left on level 1 when you lose, and there are 14 bricks on level 1, then your second attempt will be asking you to break 17 bricks, which is obviously impossible because there are only 14.
I have tried to initialize bricksLeft in the Start method but this makes it start at 1, even if there are 14, and if you beat the level, then on the next level it starts at 0. So it just wants you to break one brick to win if I do that.
I’ve tried making an if statement to only add to bricksLeft if it is equal to 0, which had the same effect.
I’ve looked over the end state code and I’m pretty sure I’m doing everything the same way Ben did it. Only difference was I was using bricksLeft = bricksLeft + 1; instead of bricksLeft++;, so I figured I would change it to Ben’s format but this didn’t change anything. So I’m stuck and I hope someone here can help me.
Here’s the code
https://pastebin.com/NgTfX67d