Countdown timer question

Has anyone else tried to make a countdown timer that resets at the end of the countdown? My son is working on a game in which each level last 20 seconds. If you survive 20 seconds, you go on to the next level, and the countdown is reset. But the “start countdown” doesn’t seem to get executed if it’s contained inside an “on countdown end”. Any thoughts about what can be done?

Does the player lose a life if they run out of time? It might be easier if you post the code you have already either as screenshot or published link from Share.

Oh that’s an annoying bug, will fix. For now, here’s a quick workaround (if he’s okay with using a gray block for now): https://makecode.com/_fmH8oFD2u1DP

info.onCountdownEnd(function () {
    control.runInParallel(function () {
        info.startCountdown(20)
    })
})
info.startCountdown(3)

The difference there is that in the on countdown end I’m calling a function that will ‘delay’ the resetting of the countdown until after the current stuff is done - in this case, that’s until after the game resets the countdown timer on its own. Just copying and pasting the three lines inside of the on countdown end and changing the time in the countdown to however many seconds they want should be good for now

Here’s the fix in case your curious: https://github.com/microsoft/pxt-common-packages/pull/1066

1 Like

On the subject of countdown timers, has there been any discussion on choosing the number of decimal places for the value shown in HUD?