-
Bug
-
Resolution: Awaiting Response
-
None
-
1.20.4
-
None
-
Macos Sonoma
-
Unconfirmed
-
(Unassigned)
While coding with mcfunctions, I used macros to simplify the code because it gets heavy really fast.
I was doing a loop that goes through the enderchest when I noticed it wasn't working as it should.
Here are the commands
execute unless score foo slotloop matches 0..26 run return 0 $execute as @a run data modify entity @e[name="storage",type=item_display,limit=1] item set from storage storage EnderItems[{Slot:$(slotloop)b}] $execute as @a run item replace entity @s enderchest.$(slotloop) from entity @e[name="storage",type=item_display,limit=1] container.0 execute as @a run data modify entity @e[name="storage",type=item_display,limit=1] item set value {id:"minecraft:air",Count:1b} scoreboard players operation foo slotloop += foo 1 execute store result storage variables slotloop int 1 run scoreboard players get foo slotloop function player:func with storage variables
I theory, this code should go through all the slots then stop at 27 because It hits the return.
While the code replaces the $(slotloop), it analyses the syntax at the same time, totally ignoring the first condition, making it not work.
Part of the debug code with the error:
[R = 27] scoreboard players operation foo slotloop += foo 1 [C] execute store result storage variables slotloop int 1 run scoreboard players get foo slotloop [M] foo has 27 [slotloop] [R = 27] execute store result storage variables slotloop int 1 run scoreboard players get foo slotloop [C] function rayan223:bedwars/shop/load_menu/tmp with storage variables [M] While instantiating macro rayan223:bedwars/shop/load_menu/tmp: Command 'execute as @a run item replace entity @s enderchest.27 from entity @e[name="storage",type=item_display,limit=1] container.0' caused error: Unknown slot 'enderchest.27'
To reproduce:
- create a datapack
- copy the code above and launch it with the following code
kill @e[name="storage",type=item_display,limit=1] summon item_display ~ ~ ~ {CustomName:'{"text":"storage"}'} scoreboard players set foo slotloop 0 scoreboard players set foo 1 1 execute store result storage variables slotloop int 1 run scoreboard players get foo slotloop function player:func with storage variables
I could just replace the last line of the code with
execute unless score foo slotloop matches 27 run function player:func with storage variables
but the fact it is working that way isn't natural