Add a timer

mechanics space polish and systems

How to implement this Pattern in MakeCode

Simple Timer for each level

Drag in from the Info section a block that reads countdown into the createLevels function.

Because this is in the createLvels function rather than in the on start function, this timer will reset everytime you reach a new level.

add timer

Have different timer values for each level

One classic way of adding challenge to a game is to ask your player to solve the next level of your game in less time. If you want to have different values for your timer for each level. We will create an array variable which will contain a list of the different times.

From Advanced > Arrays drag in a set list to array of block to the end of the on start block above the call createLevels block.

{width=90%}

Then change the variable list to one called levelTimes by clicking on it and selecting New Variable. Then change the times for each level. I’m setting the first level time to be 20 and the next one to be 15.

If you haven’t already drag in from the Info section a block that reads countdown into the createLevels function for each level. Next from Advanced > Arrays drag in a list get value at block and add it to the countdown block, and include your
levelTimes value at level, as you can see in the screenshot below.

Test your Changes and Next Steps

Test your game to check that your changes have the desired behaviour and that there are no side effects. To check that you are making the most of this pattern you can ask yourself the following question/s:

This Game Pattern is one of many allowing you to make improvements to your platform game and to learn coding and wider computing concepts. Find more on the Game Pattern page.

Some next steps you might want to add may be add more Levels. If you do that then you will need to look at the pattern to add different timings for different levels.