Command Timers

experimental

WARNING

This document covers experimental features, for 1.19.10+ mcfunctions.

Introduction

When creating mechanics or waiting for a set amount of time, it can be useful to create timers using only mcfunction files.

TIP

This page is for using commands to create timers, for entity timers, look at this page

How to make them

Start timer

BP/functions/timer_start.mcfunctionCopy
scoreboard objectives add timer dummy
scoreboard players set value timer 100
1
2

To start your timer, you need to create the scoreboard, and set the value that you are going to count down from.

The time left on the timer (currently set here as 100) should be in ticks.

20 ticks = 1 second (5s * 20 = 100)

Counting Down

BP/functions/timer_tick.mcfunctionCopy
scoreboard players remove value timer 1
execute if score value timer matches 0.. run function timer_events
execute if score value timer matches -1 run scoreboard objectives remove timer
1
2
3

Each tick, you want the timer to go down by 1. And, as long as the timer is above 0, you run the timer events. Once the timer gets to -1, remove the scoreboard

BP/functions/tick.jsonCopy
json
{
    "values": [
        "timer_tick"
    ]
}
1
2
3
4
5

In order to get the timer_tick function to run every tick, you need to include it in your tick.json file.

Running commands when the timer is over

BP/functions/timer_events.mcfunctionCopy
execute if score value timer matches 0 run function timer_up
1

Inside your timer_events file, you want to run a command once the timer reaches 0. The timer_up function include the commands you want to run once it has finished.

Running commands when the timer is running

You could also run commands while the timer is running:

BP/functions/timer_events.mcfunctionCopy
execute if score value timer matches 50 run say Half Way!
execute if score value timer matches 0 run say Finished!
1
2

End result

You can also view an example timer pack here:

Download Example Pack

Contributors

SmokeyStackTheItsNamelessHatchibombotarMedicalJewel105