I have a an area with lots of armour stands. Under each one is a dispenser with 1 – 54 items in the first slot, which is its sort of 'id'.
I need to temporarily save the number of items in each of those dispensers to a scoreboard which I am doing like so:
execute as @e[tag=char] at @e[tag=char] store result score @s temp run data get block ~ ~-1 ~ Items[0].Count
however, no matter the number of items inside or anything, it will always store a 0.
I run one similar command before which is:
execute as @e[tag=getblock] at @e[tag=getblock] unless block ~ ~-1 ~ minecraft:air store result score blockCount load run data get block ~ ~-1 ~ Items[0].Count
and this runs perfectly. There is only one amour stand with that tag but that shouldn't matter because I am running the other command using @s
which will just use the UUID of the entity.
What could be the reason for this?
Best Answer
If there is more than one armour stand, your
at
argument should be@s
instead of@e[tag=char]
.It's a complicated explanation why.
Place down two armour stands in your test world, name them
One
andTwo
respectively, and tag themtest
. Let's run a few commands on them (paste them into your chat):Result:
Now let's try using
at
instead ofas
:Result:
It looks like the command is executed twice, by your player, once at each position.à
Now let's combine them. Try the following:
... and you get 4 messages, 2 from each armour stand.
What is happening with your old command is that each armour stand is executing the
/data get
with each armour stand, not with itself. So armour stand 1 will execute/data get
with all the other armour stands, not just itself.Fixed command: