2

I made a sonic map in 1.12 commands, and I'm now trying to transfer it to 1.13 commands instead.

I'm trying to detect how many blocks were affected by the command that was run (previously "/stats") by using the new /execute store result. As you can see, it didn't work cause the "test" scoreboard shows 84 instead of 18.

What I'm thinking is that it's adding the time to the scoreboard as well. I've tried looking up solutions on the wiki, youtube, etc.

But can't wrap my head around how it works!

I would appreciate it if someone talented at commands could help me. Command, NBT, and scoreboard.

there is a system that collects gold with execute as @a [x=666704,dx=138,y=44,dy=23,z=981,dz=12] at @s run fill ~1 ~1 ~1 ~-1 ~-1 ~-1 air replace gold_block problem is, it can remove 2 gold blocks though getting only 1 gold ingot. That's why I want to get the input from the command and store the result on a scoreboard. Referring to what MegaCrafter10 said, I tested his command(execute store result score <player> <objective> run fill <x> <y> <z> <x2> <y2> <z2> <block> ) and I found another problem, It sets back to 0 every time there is no output(it's in a repeating command block). Would it be able to store how many blocks of gold it has filled away without it being reset? Instead, rising higher by 1 for each gold?

1 Answer 1

4

LastOutput represents the last line of output generated by the command block. Since that line is a string, the /execute store command returns the length of that line (which is 84 in your case).

Instead of reading the number from the output, you can access that number directly:

execute store result score <player> <objective> run fill <x> <y> <z> <x2> <y2> <z2> <block>

this will store the amount of blocks affected by the /fill command into the specified objective.

Edit:

if you want to keep track of how many blocks we're affected in total, here is how you can do that.

You need two scoreboard objectives of type dummy. I will call mine "count" and "total". Once you have two objectives, place down a command block (it can be an impulse or repeating command block) and paste this command in:

execute store result score @p count run fill ...

attach a chain command block to the one you just placed down and set it to always active. Paste this in:

execute as @p run scoreboard players operation @s total += @s count

this will store the number of affected blocks into "count" and add its value to "total".

9
  • String length, really? Wow, I would have not expected that. I wonder if that can be used for something... (Also, this is one of those answers that retroactively makes the question much more interesting than originally thought.) Commented Apr 10, 2020 at 2:13
  • there is a system that collects gold with execute as @a [x=666704,dx=138,y=44,dy=23,z=981,dz=12] at @s run fill ~1 ~1 ~1 ~-1 ~-1 ~-1 air replace gold_block problem is, it can remove 2 gold blocks though getting only 1 gold ingot. That's why I want to get the input from the command and store the result on a scoreboard. I tested your command and I found another problem, It sets back to 0. Would it be able to store how many blocks of gold it has filled away without it being reset? Instead, rising higher by 1 for each gold? Commented Apr 10, 2020 at 7:51
  • @AaronKanaron Are you using a repeating command block? If so, the score will reset because the command block is trying to replace the blocks over and over again but there is nothing to replace. One thing you can do is check if the score is 0 before running the command. Here's an example: "/execute if score <player> <objective> matches 0 run execute store ...". This should stop the command block from overwriting the previous score. Commented Apr 10, 2020 at 11:05
  • @FabianRöling it is indeed an interesting feature (if it even is a feature). But I can't think of anything useful you could do with this. It would be nice if Mojang gave us the ability to convert this stringified JSON object back to JSON and access the values stored in its fields instead. Commented Apr 10, 2020 at 11:19
  • Can't i remove the "run execute", more like "...matches 0 store..." Commented Apr 10, 2020 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .