← All of the Docs The basics
Loops
Guide and examples
loop 3 times:
send "Hello!"
for each {_name} in sorted server.players:
send "&7 - &f%{_name}%"
loop all players: runs its block once for every player who is online:
loop all players:
add 10 to {%loop-player%.coins}
send "&a%player.name% gave you 10 coins!" to loop-player
Inside any loop, loop-value is what the loop is on: the number of the round, the element of the list, the player.
loop 3 times:
send "&7Round %loop-value%"
loop from 10 to 1:
send "&e%loop-value%..."
wait 1 second
send "&aGo!"
loop from 0 to 100 by 25:
send "&7%loop-value%%"
loop {queue}:
send "&7%loop-index%. &f%loop-value%"
In a loop inside a loop the values are numbered from the outside in: loop-value-1 belongs to the first loop, loop-value-2 to the one inside it.
loop from 1 to 3:
loop from 1 to 3:
send "&7%loop-value-1% x %loop-value-2% = &f%loop-value-1 * loop-value-2%"
A loop can take some of what it goes through only, and say what to do when there was nothing:
loop all players with permission "staff.alerts":
send "&c%player.name% needs help." to loop-player
else:
send "&7No staff are online."
loop {queue} where loop-value is not player.name:
send "&7%loop-index%. &f%loop-value%"
loop blocks within 3 blocks of player:
if block at loop-value is "fire":
set block at loop-value to air
A counter, and a table's names and values:
loop 5 times with {_i}:
send "&7Round %{_i}%"
for each {_name}, {_place} in {warp}:
send "&b%{_name}% &7is at %{_place}%"
break and continue steer a loop from inside:
for each {_name} in {queue}:
if {_name} is "Steve":
continue
if size of {_picked} >= 3:
break
append {_name} to {_picked}
A while loop repeats for as long as its condition holds:
set {_n} to 3
while {_n} > 0:
send "&e%{_n}%..."
wait 1 second
subtract 1 from {_n}
send "&aGo!"
loop <n> times:repeats its block. To protect the server it refuses more than 100,000 (loop-limitinconfig.ymlchanges that) repetitions.for each {_item} in <list>:runs its block once per element, with the element in the local.loop <n> times with {_i}:puts the number of the round, from 1, in the local.loop from <a> to <b>:counts from the one number to the other, both included, andloop-valueis the number:loop from 1 to 5is 1, 2, 3, 4, 5 andloop from 5 to 1is 5, 4, 3, 2, 1.by <n>is how far apart the numbers are:loop from 0 to 10 by 5is 0, 5, 10, andloop from 0 to 1 by 0.25works as well. Which way it counts is said by the two ends, sobyis never negative, and it stops at the last number that does not pass the end:loop from 10 to 0 by 3is 10, 7, 4, 1. The same limit as forloop <n> timesapplies.loop <list>:goes through a list without a local to name:loop {queue}:,loop sorted server.players:. The element isloop-value. Given a number it goes round that many times, soloop {_n}:isloop {_n} times:.loop-valueis what the loop around the line is on. Inloop <n> timesandwhilethat is the number of the round; inloop fromthe number; infor eachandloop <list>the element (withfor each {_key}, {_value}the value); inloop all playersthe player, likeloop-player; incountdownthe seconds left; inrepeatthe round. In text it is%loop-value%, and it can be writtenloop_value.loop-indexis which round the loop is on, from 1, whatever the loop goes through:"%loop-index%. %loop-value%"numbers a list.- In a loop inside a loop,
loop-value-1is the value of the outermost loop,loop-value-2of the loop inside it, and so on;loop-index-1,loop-index-2likewise. The plainloop-valueis always the innermost loop's, the one the line is directly in. A number that no loop has (loop-value-3inside two loops) is refused when the script loads, and so isloop-valueoutside a loop. To subtract from it, leave a space:loop-value - 1. for each {_key}, {_value} in {table}:goes through every name under a table and the value stored there, for saved tables ({warp},{%player%.homes}) and local ones ({_data}) alike.repeat every <time> for <time>:runs its block, waits, and runs it again until the time is up; see Waiting.countdown 10 seconds:is arepeatthat counts: its block runs once a second andseconds leftis 10, then 9, down to 1. The lines after the block run when it has reached the end, so they are where "Go!" belongs.breakends it early.once every 5 seconds for player:runs its block at most that often for each player, which is a cooldown around any lines you like;else:under it is where "wait a moment" goes. It can also be writtenat most once every 5 seconds for player:.once for player:runs its block the first time a player gets there and never again;once per day for player:once in each day by the server's calendar, so a reward taken at 23:59 can be taken again at 00:00. Put a name afteronce(once "daily" per day for player:) if the block may be moved or changed later: without one HyperScript tells theonceblocks of a script apart by what they say, and one that is rewritten counts as new.else:works as afterif.loop all players:goes through whoever is online when it starts. Inside it,loop-player(in text,%loop-player%) is the name of the player the loop is on (it can also be writtenloop playerorloop_player, which are the same word), andplayeris still whoever ran the command or caused the event. Everything that takes a player takesloop-player:loop-player's location,health of loop-player,{%loop-player%.coins},send "..." to loop-player,loop-player has permission "x".loop-numberis which round the loop is on, starting at 1; it is the same asloop-indexand works in every loop.loop all playerstakes what says which of them:with permission "<node>",in world "<name>",within <n> blocks of <location>, orwhere <condition>, in whichloop-playeris each player in turn:loop all players where health of loop-player < 5:. The same works wherever something is done to all players:send "..." to all players with permission "staff",send title "Go!" to all players in world "arena".loop <list> where <condition>:goes through the elements the condition holds for only; in the conditionloop-valueis the element.loop-indexthen counts the ones that were kept.- Anything that gives a list can be looped over:
loop blocks within 3 blocks of player:andloop blocks from {_a} to {_b}:(eachloop-valueis the location of a block, soblock at loop-valueis what is there),loop entities within 10 blocks of player:,loop players within 10 blocks of player:,loop items in inventory of player:. Blocks are counted before the loop starts, and more thanloop-limitof them are refused. else:directly under a loop runs when the loop never went round: the list was empty or was never set, nobody was online, the condition of awhiledid not hold the first time.while <condition>:checks the condition before every round.break loop 1andcontinue loop 1reach a loop further out, by the same numbers asloop-value-1: 1 is the outermost.break loop 1leaves that loop and every loop inside it;continue loop 1ends the loops inside it and starts its next round. They take a condition like the plain ones:break loop 1 if {_found} is set.breakleaves the loop it is in and carries on after it.continueskips the rest of this round and starts the next. In nested loops both act on the innermost one.stopinside a loop ends the whole trigger, not just the loop.- All three take a condition on the same line:
stop if {_coins} < 100,continue if loop-player is player.name,break unless {_found} is set.stop with <text>tells the player something first:stop with "&cNot enough coins." if {_coins} < 100. - A
whileloop that goes round 100,000 times (loop-limitinconfig.yml) without awaitis stopped with an error in the console, so a condition that never becomes false cannot freeze the server. A loop that waits each round may run for as long as you like.