2

I want to create a fairly long timer with

   /title @a actionbar §lGame starts in §a01:00

But I do not want to have to use 61 command blocks, but still want a second by second countdown displayed constantly without any gaps.

How would I do this only with command blocks in a compact fashion?

1 Answer 1

3

You can store seconds and minutes in a scoreboard as if they were real players. The same is for any variables you want.

Also, you can use /titleraw command because raw JSON text format supports player's score embedding.


Setup

Before building the mechanism itself, you should create a scoreboard where the variables will be stored:

/scoreboard objectives add vars dummy

Next, let's set initial values for the minutes and seconds:

/scoreboard players set minutes vars 1

/scoreboard players set seconds vars 0

The mechanism

The mechnanism

[1] (formatted time printing): titleraw @a actionbar {"rawtext": [{"text": "Remaining Time: 0"}, {"score": {"name": "minutes", "objective": "vars"}}, {"text": ":"}, {"score": {"name": "seconds", "objective": "vars"}}]}

NB: if your timer is longer than 09:59, you should delete the zero at "Remaining Time: 0".

[2] (seconds decrementing): scoreboard players remove seconds vars 1

[3] (test for seconds reached -1; in this way, it goes to [4] by comparator): scoreboard players test seconds vars -1 -1

[4] (setting seconds to 59): scoreboard players set seconds vars 59

[5] (minutes decrementing): scoreboard players remove minutes vars 1

[6] (test for minutes reached -1; in this way, it blocks the repeater clock): scoreboard players test minutes vars -1 -1

Restarting the timer

To restart it, you need to set initial values for minutes and seconds as I said above and replace the comparator between [3] and [4] command blocks.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .