#(hmoe) looping over a data script

16 messages · Page 1 of 1 (latest)

idle patio
#

i want to run a give command, with a bunch of different values. i want the loop to fill with each value. I've almost got it working, but not quite.

enchantment_give_task:
    type: task
    script:
    - foreach <script[enchantment_data].data_key[enchantment]> as:enchantment:
        - execute as_server "ae give <player.name> <script[enchantment_data].data_key[enchantment]> 1"

enchantment_data:
  type: data
  enchantment:
  - abiding
  - aegis
  - ambit
summer vigilBOT
#

(hmoe) looping over a data script

summer vigilBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.

idle patio
#

to be clear, what I want to happen is for each item in the list, run the command with that item in the list. right now, <script[enchantment_data].data_key[enchantment]> fills with the entire data of the enchantment list

vestal reef
#

!c foreach usage

opal needleBOT
# vestal reef !c foreach usage
Group

queue

Syntax

foreach [stop/next/<object>|...] (as:<name>) (key:<name>) [<commands>]

Short Description

Loops through a ListTag, running a set of commands for each item.

Use to run commands 'for each entry' in a manually created list of objects/elements.
- foreach <[some_entity]>|<[some_npc]>|<[player]> as:entity:
    - announce "There's something at <[entity].location>!"
Use to iterate through entries in any tag that returns a list.
- foreach <player.location.find_entities[zombie].within[50]> as:zombie:
    - narrate "There's a zombie <[zombie].location.distance[<player.location>].round> blocks away"
Use to iterate through a list of players and run commands automatically linked to each player in that list.
- foreach <server.online_players> as:__player:
    - narrate "Thanks for coming to our server, <player.name>! Here's a bonus $50.00!"
    - money give quantity:50
vestal reef
#

Check the examples

#

you specifying as:enchantment so you return the value within the loop via <[enchantment]>

idle patio
#

ahhh that makes total sense

#

i had a look at the examples and felt a bit confused. loops have always thrown me for a loop

drowsy thistle
#

Did you put the 😂 to your own message 😭😭😭😭😭

idle patio
#

yes.

random gladeBOT
#
Resolved

Thread closed as resolved.

random gladeBOT
#
Thread Reopened

Thread was manually reopened by @slender monolith.

left thistle
#

@slender monolith please do not reopen closed threads without a reason