The bug
Using execute store result to get the number of commands ran in a function always outputs 1 if ran inside of another function.
Setup
scoreboard objectives add my_objective dummy
scoreboard objectives setdisplay sidebar my_objective
Use attached datapack containing two functions:
my_function.mcfunction
say 1
say 2
say 3
say 4
say 5
test.mcfunction
execute store result score player my_objective run function store:my_function
How to reproduce
1. Run the following command in chat, notice score gets set to 1
/function store:test
2. Run this command in chat or in a command block, notice score gets set to the amount of commands ran
/execute store result score player my_objective run function store:my_function
Expected output
I expected the execute store result to behave the same way inside of a function as it does in chat or in a command block.
Actual output
The store gets set to 1 if the execute store command is inside of a function regardless of the amount of commands ran.
Linked issues
is duplicated by 2
Attachments
Comments 13
In fact, this is a duplicate of MC-130375
can confirm for 1.19.3
It actually seems to go beyond return and also affects success, where success would store the success value of the last command run in the function instead of whether the function was run or not.
This is different from the behavior in chat and commandblocks, where it seems to return 1 for success if the function is run successfully, independent of the final commands success.
This needs some tricky fix... the execution of function would need to return some sort of lazy integer (atomic integer? completable future with integer?) and populate the value in the main dfs code body.