Pass Command Into FOR Loop and Read Current Value of i
Is there a way I can call
Continue to help postsplib:for
with a command that takes a numeric value, and have the command read from i
In my specific example, I want to pass a function that applies to every slot of the inventory. stop = 36
The command applying to every inventory slot takes a slot
value (in this case, the value of i
), and cmd
, which is a command to apply to each slot.
splib:for
# Create objective scoreboard objectives add splib dummy # Call recursive helper $function splib:for_loop { stop: $(stop), cmd: "$(cmd)" } # Remove objective scoreboard objectives remove splib
splib:for_loop
# if $i in $range # run command $execute if score i splib matches ..$(stop) run $(cmd) # $i++ scoreboard players add i splib 1 # if $i in $range # run $self $execute if score i splib matches ..$(stop) run function splib:for_loop { stop: $(stop), cmd: "$(cmd)" }