HyperScript
Docs

← All of the Docs The basics

Waiting

effectwait <duration>since 1.5.2

Any duration: wait 10 ticks, wait 5 seconds, wait 1 minute 30 seconds

wait 3 seconds
Try it
effectwait <number> secondssince 1.5.2

The number may be a variable: wait {_delay} seconds

set {_delay} to 5
wait {_delay} seconds
Try it
effectwait until <condition> [for at most <duration>]since 1.7.0

Pause until it is true

wait until block at (location below player's location) is "gold_block" for at most 30 seconds
Try it
effectwait between <duration> and <duration>since 1.7.57

Pause for some time between the two, another every time: wait between 1 and 3 seconds, wait between 10 ticks and 1 second

command /fish:
    trigger:
        send "&7You cast the line..."
        wait between 2 and 6 seconds
        send "&bA bite!"
Try it
structureafter <duration>:since 1.7.57

Run the block under it that much later, on its own: the lines below the block carry on at once. Inside it the local variables are as they were when the after was reached

on player join:
    after 3 seconds:
        send "&aWelcome, %player.name%."
Try it
effectrun <function>(...) in <duration>since 1.7.0

Call a function later

function remind({_who}):
    send "&eTime is up!" to {_who}
command /timer:
    trigger:
        run remind(player.name) in 30 seconds
Try it
effectrun <function>(...) in <duration> as <name>since 1.7.1

The same, under a name it can be called off by

function end_boost({_who}):
    set walk speed of {_who} to 0.2
command /boost:
    trigger:
        set walk speed of player to 0.4
        run end_boost(player.name) in 30 seconds as "boost %player.name%"
Try it
expressionschedule <function>(...) in <duration>since 1.7.10

Like run ... in, but written down: the call still happens after a restart. Add as <name> to be able to replace it or call it off

function end_vip({_who}):
    delete {%{_who}%.vip}
    send "&7Your VIP time is over." to {_who}

command /vip <target:player>:
    permission: "vip.give"
    trigger:
        set {%arg.1%.vip} to true
        schedule end_vip(arg.1) in 30 days as "vip %arg.1%"
Try it
effectcancel schedule <name>since 1.7.10

Call off a named schedule that has not happened yet

cancel schedule "vip %arg.1%"
Try it
expressiontime until schedule <name>since 1.7.44

How long a named schedule still has; unset if nothing waits under that name, so is set says whether one is pending

set {_left} to time until schedule "restart"
Try it
effectcancel run <name>since 1.7.1

Call off a named run that has not happened yet

cancel run "boost %player.name%"
Try it
structurerepeat every <duration> for <duration>:since 1.7.0

Run a block now and then again at each interval

repeat every 1 second for 10 seconds:
    send title "&e%{_n}%" to all players
    subtract 1 from {_n}
Try it
structurecountdown <duration>:since 1.7.52

Run a block once a second, with seconds left counting down to 1; what comes after the block runs when it is over

countdown 5 seconds:
    send title "&e%seconds left%" to player
send title "&aGo!" to player
Try it
structureonce for <who>:since 1.7.52

Run a block the first time only, for each player; else: under it runs every other time

on player join:
    once for player:
        send "&6Welcome! &7Type /help to get started."
Try it
structureonce per day for <who>:since 1.7.52

The same once in each day; also per hour, per week, per month, or per 30 minutes for that long after the last time

command /daily:
    trigger:
        once per day for player:
            add 100 to {%player%.coins}
            send "&a+100 coins."
        else:
            send "&7You have had today's reward."
Try it
structureonce:since 1.7.52

Without for: once for the whole server

on load:
    once:
        log "This server ran HyperScript for the first time."
Try it
Guide and examples

wait pauses the trigger it is in, then carries on with the next line. Only that trigger pauses; the server and every other script keep running.

command /launch:
    trigger:
        send "&eLaunching in 3 seconds..."
        wait 3 seconds
        execute console command "effect give %player.name% minecraft:levitation 2 20"
        wait 2 seconds
        send "&aEnjoy the view."
SyntaxMeaning
wait <duration>Any duration: wait 10 ticks, wait 5 seconds, wait 1 minute 30 seconds
wait <number> secondsThe number may be a variable: wait {_delay} seconds
  • wait works anywhere, including inside if, loops, GUI click blocks and async:. Local variables keep their values across it.
  • Time passes while a trigger waits. The player may have moved or logged out, and variables may have been changed by other scripts, so check again afterwards if it matters.
  • After a wait, the event that started the trigger is over: cancel event and statements that change the event, such as set join message, no longer have any effect.
  • The shortest wait is one tick (a twentieth of a second). Waits do not survive a server restart or a script reload.

Waiting for something. wait until pauses until a condition holds, looking again four times a second:

send "&7Stand on the gold block to start."
wait until block at (location below player's location) is "gold_block" for at most 30 seconds
send "&aGo!"

It gives up after the time given with for at most, or after five minutes if none is given, and the script carries on either way; test the condition again afterwards if it matters.

Doing something later, and again. run calls a function after a delay without making the rest of the trigger wait, and repeat runs a block at intervals for a while:

function unfreeze_later({_who}):
    unfreeze {_who}
    send "&aYou can move again." to {_who}

command /timeout <player>:
    permission: "staff.timeout"
    trigger:
        freeze arg.1
        run unfreeze_later(arg.1) in 30 seconds

command /countdown:
    trigger:
        set {_n} to 10
        repeat every 1 second for 10 seconds:
            send title "&e%{_n}%" to all players
            subtract 1 from {_n}
SyntaxEffect
wait until <condition> [for at most <duration>]Pause until it is true
wait between <duration> and <duration>Pause for some time between the two, another every time: wait between 1 and 3 seconds, wait between 10 ticks and 1 second
after <duration>:Run the block under it that much later, on its own: the lines below the block carry on at once. Inside it the local variables are as they were when the after was reached
run <function>(...) in <duration>Call a function later
run <function>(...) in <duration> as <name>The same, under a name it can be called off by
schedule <function>(...) in <duration>Like run ... in, but written down: the call still happens after a restart. Add as <name> to be able to replace it or call it off
cancel schedule <name>Call off a named schedule that has not happened yet
time until schedule <name>How long a named schedule still has; unset if nothing waits under that name, so is set says whether one is pending
cancel run <name>Call off a named run that has not happened yet
repeat every <duration> for <duration>:Run a block now and then again at each interval
countdown <duration>:Run a block once a second, with seconds left counting down to 1; what comes after the block runs when it is over
once for <who>:Run a block the first time only, for each player; else: under it runs every other time
once per day for <who>:The same once in each day; also per hour, per week, per month, or per 30 minutes for that long after the last time
once:Without for: once for the whole server