Minecraft:Commands/stopwatch: Difference between revisions
More actions
Remove broken links to missing pages |
Sync: updated from Minecraft |
||
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{exclusive|Java}} | {{exclusive|Java}} | ||
{{Infobox command | {{Infobox command | ||
| name = stopwatch | | name = stopwatch | ||
| oplevel = | | oplevel = 2 | ||
}} | }} | ||
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: | ||
* When displayed, it is presented in seconds with 3 decimal places (e.g. <code>43.961s</code>). | * When displayed, it is presented in seconds with 3 decimal places (e.g. <code>43.961s</code>). | ||
* While any | * While any number can be used as the <code>scale</code> argument, a <code>scale</code> with a value >1000 is not useful to extract additional precision in the integer return value. | ||
== Syntax == | == Syntax == | ||
<code>/stopwatch ...</code> | |||
: <code> | |||
: <code> | :<code>... create <id></code> - Creates a stopwatch, which immediately begins running | ||
:<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 == | ||
| Line 32: | Line 65: | ||
{{Navbox commands}} | {{Navbox commands}} | ||
de:Befehl/stopwatch | [[Minecraft:de:Befehl/stopwatch]] | ||
ja:コマンド/stopwatch | [[Minecraft:ja:コマンド/stopwatch]] | ||
pt:Comandos/stopwatch | [[Minecraft:pt:Comandos/stopwatch]] | ||
zh:命令/stopwatch | [[Minecraft:zh:命令/stopwatch]] | ||
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
scaleargument, ascalewith 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
- Specifies the stopwatch to operate on.
- Must be a Minecraft:resource location for an unregistered content.
- Specifies the value to multiply the returned value by, e. g.
stopwatch query foo:bar 20would 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
Minecraft:de:Befehl/stopwatch Minecraft:ja:コマンド/stopwatch Minecraft:pt:Comandos/stopwatch Minecraft:zh:命令/stopwatch