Name | Foreach |
Related Guide Page | https://guide.denizenscript.com/guides/basics/loops.html |
Syntax | foreach [stop/next/<object>|...] (as:<name>) (key:<name>) [<commands>] |
Short Description | Loops through a ListTag, running a set of commands for each item. |
Full Description | Loops through a ListTag of any type. For each item in the ListTag, the specified commands will be ran for that list entry.
Alternately, specify a map tag to loop over the set of key/value pairs in the map, where the key will be <[key]> and the value will be <[value]>. Specify "key:<name>" to set the key definition name (if unset, will be "key"). Specify "as:<name>" to set the value definition name (if unset, will be "value"). Use "as:__player" to change the queue's player link, or "as:__npc" to change the queue's NPC link. Note that a changed player/NPC link persists after the end of the loop. To end a foreach loop, do - foreach stop To jump immediately to the next entry in the loop, do - foreach next Note that many commands and tags in Denizen support inputting a list directly, making foreach redundant for many simpler cases. Note that if you delay the queue (such as with wait or ~waitable) inside a foreach loop, the loop can't process the next entry until the delay is over. This can lead to very long waits if you have a long list and a wait directly in the loop, as the total delay is effectively multiplied by the number of iterations. Use run if you want to run logic simultaneously for many entries in a list in a way that allows them to separately wait without delaying each other. |
Related Tags | <[value]> to get the current item in the loop
<[loop_index]> to get the current loop iteration number
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Group | queue |
Source | https://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/scripts/commands/queue/ForeachCommand.java#L31 |