Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Commands/stopwatch: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Sync: updated from Minecraft
SyncBot (talk | contribs)
Sync: updated from Minecraft
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{exclusive|Java}}
{{exclusive|Java}}
{{stub}}
{{Infobox command
{{Infobox command
| name = stopwatch
| name = stopwatch
Line 6: Line 5:
}}
}}


Allows manipulation of stopwatches to keep track of ''real'' time — the time measured is not affected by the game's tick rate (i.e. pausing, {{cmd|tick}}, or even server lag).
Allows manipulation of stopwatches to keep track of ''real'' time — the time measured is not affected by the game's tick rate (i.e. pausing, {{cmd|tick}}, or even server lag). This makes it useful to detect and compensate for lag e.g. when programming functions in a [[Minecraft:data pack]].


Their elapsed time can be checked against a value range using <code>[[Minecraft:Commands/execute#(if%7Cunless) stopwatch|/execute (if|unless) stopwatch]]</code>.
== Usage ==
The time is calculated with millisecond precision. Therefore:
The time is calculated with millisecond precision. Therefore:


Line 14: Line 16:


== Syntax ==
== Syntax ==
* '''''Java Edition'''''
<code>/stopwatch ...</code>
: <code>stopwatch create <id></code> - Creates a stopwatch, which immediately begins running
 
: <code>stopwatch query <id> [<scale>]</code> - Gets the value of the stopwatch, the amount of time since it was created/restarted. <code>scale</code> does not affect the displayed value in chat, but does affect the value returned e.g. for {{cmd|execute store result...}}. If the return value would exceed 32-bit signed integer limits (<-2147483648 or >2147483647), it is clamped.
:<code>... create <id></code> - Creates a stopwatch, which immediately begins running
: <code>stopwatch restart <id></code> - Restarts a stopwatch
 
: <code>stopwatch remove <id></code> - Removes a stopwatch
:<code>... query <id> [<scale>]</code> - Gets the value of the stopwatch, the amount of time since it was created/restarted in seconds.
 
:<code>... restart <id></code> - Restarts a stopwatch
 
:<code>... remove <id></code> - Removes a stopwatch
 
== Arguments ==
{{Argument|id|resource_location}}
: Specifies the stopwatch to operate on.
: Must be a [[Minecraft:resource location]] for an unregistered content.
{{Argument|scale|double}}
 
:Specifies the value to multiply the returned value by, e. g. <code>stopwatch query foo:bar 20</code> would get the elapsed time in ticks<ref>https://www.minecraft.net/en-us/article/minecraft-snapshot-25w42a</ref>. Does not affect the value displayed in chat. If the return value would exceed 32-bit signed integer limits (<-2147483648 or >2147483647), it is clamped.
 
== Result ==
{{Result table|onlyje=1}}
{{Result table|The command is incomplete, or any argument is not specified correctly.|unparseable}}
{{Result table|The specified stopwatch already exists.|fail|cmd=stopwatch create ...}}
{{Result table|The specified stopwatch doesn't exist.| |cmd=stopwatch query ...}}
{{Result table|The specified stopwatch doesn't exist.| |cmd=stopwatch restart ...}}
{{Result table|The specified stopwatch doesn't exist.| |cmd=stopwatch remove ...}}
{{Result table|succeed|cmd=}}
{{Result table}}
 
== Output ==
{{Output table}}
{{Output table|On fail|0|0|0|edition=je}}
{{Output table|On success|1|1|1|cmd=stopwatch create ...}}
{{Output table|On success|1|1|The value of the stopwatch, multiplied by <scale>, then floored|cmd=stopwatch query ...}}
{{Output table|On success|1|1|1|cmd=stopwatch restart ...}}
{{Output table|On success|1|1|1|cmd=stopwatch remove ...}}
{{Output table}}


== History ==
== History ==

Latest revision as of 11:04, 4 September 2026

Template:Exclusive Template:Infobox command

Allows manipulation of stopwatches to keep track of real time — the time measured is not affected by the game's tick rate (i.e. pausing, Template:Cmd, or even server lag). This makes it useful to detect and compensate for lag e.g. when programming functions in a Minecraft:data pack.

Their elapsed time can be checked against a value range using /execute (if|unless) stopwatch.

Usage

The time is calculated with millisecond precision. Therefore:

  • When displayed, it is presented in seconds with 3 decimal places (e.g. 43.961s).
  • While any number can be used as the scale argument, a scale with a value >1000 is not useful to extract additional precision in the integer return value.

Syntax

/stopwatch ...

... create <id> - Creates a stopwatch, which immediately begins running
... query <id> [<scale>] - Gets the value of the stopwatch, the amount of time since it was created/restarted in seconds.
... restart <id> - Restarts a stopwatch
... remove <id> - Removes a stopwatch

Arguments

Template:Argument

Specifies the stopwatch to operate on.
Must be a Minecraft:resource location for an unregistered content.

Template:Argument

Specifies the value to multiply the returned value by, e. g. stopwatch query foo:bar 20 would get the elapsed time in ticks<ref>https://www.minecraft.net/en-us/article/minecraft-snapshot-25w42a</ref>. Does not affect the value displayed in chat. If the return value would exceed 32-bit signed integer limits (<-2147483648 or >2147483647), it is clamped.

Result

Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table

Output

Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table Template:Output table

History

Template:HistoryTable

Navigation

Template:Navbox commands

Minecraft:de:Befehl/stopwatch Minecraft:ja:コマンド/stopwatch Minecraft:pt:Comandos/stopwatch Minecraft:zh:命令/stopwatch