I want to use a tile and function to call the next level in a game every time the player overlaps that tile. Unfortunately, when my player overlaps the tile on first level the game automatically just moves the player to the final level. How do I get this to happen one level at a time?
Here’s the specific code I’m talking about:
Here’s the complete game if you want to see how it works:
Any help is much appreciated.
Your issue is with the if statements in nextLevel:
level2 function sets the level variable equal to 2. When that function call completes and moves on to the next
if statement its condition also evaluates to true causing
level3 to be called! This is a great example for the debugger; if you set a breakpoint at the top of the
nextLevel function and step through the code i think you’ll see exactly what’s going on.
To fix it, simply make the second
else if instead of its own
Thanks! I switched it to an else if and it works now. I never used the debugger, but I’ll give it a go next time I run into something.