pxt-arcade
pxt-arcade copied to clipboard
On update code runs when game is over
Describe the bug If a game ends before the execution of the on start block is finished, on update and on update interval code will execute indefinitely.
To Reproduce Steps to reproduce the behavior:
- Use an on start block that takes a while to execute. Using the melody blocks is an easy way to do this.
- Have some sort of game mechanic that ends the game before the on start block is finished executing. Like a countdown or overlap event.
- End the game before the on start finishes
- See that the on update events still trigger
Sample Game (beta) Open in Beta Editor
Expected behavior When the game is over, no user code should be run.
Screenshots
The issue here is pretty clear if you look at the TypeScript:
let projectile: Sprite = null
info.startCountdown(1)
music.playMelody("- - - - - - - - ", 450)
game.onUpdate(function () {
projectile = sprites.createProjectileFromSide(img`1`, 100, 0)
projectile.y = 100
})
game.onUpdateInterval(50, function () {
projectile = sprites.createProjectileFromSide(img`1`, -100, 0)
projectile.y = 20
})
The onUpdate
blocks don't run until after we have destroyed the user's scene and created a new scene to display the game over dialog. As a result, the onUpdate
blocks create sprites in the second scene.
I think the only fix here is to set some global variable that prevents new sprites from being created after Game Over is shown.
Still repros.