pxt-arcade icon indicating copy to clipboard operation
pxt-arcade copied to clipboard

On update code runs when game is over

Open ChaseMor opened this issue 5 years ago • 2 comments

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:

  1. Use an on start block that takes a while to execute. Using the melody blocks is an easy way to do this.
  2. Have some sort of game mechanic that ends the game before the on start block is finished executing. Like a countdown or overlap event.
  3. End the game before the on start finishes
  4. 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 game-over-food

ChaseMor avatar Aug 30 '19 22:08 ChaseMor

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.

riknoll avatar Oct 24 '19 23:10 riknoll

Still repros.

abchatra avatar Oct 14 '22 18:10 abchatra