mojira.dev
MC-221241

The /schedule command might be unreliable under rare conditions

The Bug

I am developing a cuistom map for Minecraft 1.16.5.
At the start of a game, the player is dropped down and a countdown takes place. This countdown uses /schedule, which will schedule the function again with 1 second of delay. There is no condition in that function.

Now, a playtester of my map experienced a bug where the countdown function only ran once: https://clips.twitch.tv/EasySnappyBulgogiSoBayed-bkiMzWw0P78LWZms
The game was still operering normally, entities moved, blocks dropped and drops could be picked up. So this was not a massive lag spike or a game crash.

These are the contents of the function in question (bingo:game/start/countdown):

execute if score $start_game.countdown bingo.tmp matches 1.. run tellraw @a {"score":{"name": "$start_game.countdown", "objective": "bingo.tmp"}}
execute as @a at @s if score $start_game.countdown bingo.tmp matches 1.. run playsound minecraft:block.note_block.pling master @s ~ ~ ~ 1 2

execute if score $start_game.countdown bingo.tmp matches 0 run function bingo:game/start/start_game

scoreboard players remove $start_game.countdown bingo.tmp 1
schedule function bingo:game/start/countdown 1s
execute if score $start_game.countdown bingo.tmp matches 1.. run tellraw @a {"score":{"name": "$start_game.countdown", "objective": "bingo.tmp"}}
execute as @a at @s if score $start_game.countdown bingo.tmp matches 1.. run playsound minecraft:block.note_block.pling master @s ~ ~ ~ 1 2

execute if score $start_game.countdown bingo.tmp matches 0 run function bingo:game/start/start_game

scoreboard players remove $start_game.countdown bingo.tmp 1
schedule function bingo:game/start/countdown 1s

Now, a few things to note:

The schedule command is the last command in that function. One possible explanation is that the function did not fully execute, for example by hitting the maxCommandChainLimit. There are however only 5 commands in this function. There is another function that is being called here, however only if the countdown score is 0. At the start, there is a tellraw printing the current state of the variable. You can see in the clip, that it printed 3, so that function could not have been executed. It could be related to the count of commands a scheduled function ran somehow not being accurate or accumulating under some conditions.

Another thing is, that the schedule command is unconditional. This however means, that typically the function will keep getting scheduled even after the countdown completed. You won't notice any of that unless you have the map running for 2^32 seconds without starting another game.
The bug however could have been caused by the function already being scheduled beforehand, and that old schedule somehow interfering with things. That seems unlikely though, as the initial execution that ran (and printed the number 3) is not a direct function call either, but a scheduled function that executes 3 seconds after another function, and that one obviously did execute.

This bug also happened about 10 minutes after a clock change due to daylight saving time, however, I doubt this has any relation to it at all, since it was not exactly at the time clocks changed.

Other than that, I can only see the schedule queue itself being unreliable under some conditions.

How to reproduce

I tried various things, such as having a function that reschedules itself for the next tick, with various amounts of intentionally caused lag, or having another function scheduling it as well with a higher delay, or changing the system time to simulate a clock change.
None of that seemed to be able to reproduce this bug.

If anyone ever experiences something similar, please do leave a comment providing as much additional information as possible

Comments 1

Nevermind, I had another function which would sometimes clear the countdown score which is used here, causing the function to do nothing when it happened

NeunEinser

(Unassigned)

Unconfirmed

Commands

1.16.5

Retrieved