mojira.dev
MC-120590

Performing an operation on a scoreboard that got its result from stats returns a constant incorrect result

Running the following code in a function:

scoreboard objectives add TempA dummy
scoreboard players set @s TempA 0
stats entity @s set SuccessCount @s TempA
testfor @a {Dimension:0}
tellraw @a [{"text":"Dims "},{"score":{"name":"@s","objective":"TempA"}}]
scoreboard players set @s[score_TempA_min=2,score_GM4_BBLoops_min=300] GM4_BBNState 6

scoreboard objectives add TempB dummy
scoreboard players set @s TempB 0
stats entity @s set SuccessCount @s TempB
testfor @a {Sleeping:1b}
tellraw @a [{"text":"Sleeps "},{"score":{"name":"@s","objective":"TempB"}}]
scoreboard objectives add TempC dummy
scoreboard players set @s TempC 0
scoreboard players operation @s TempC = @s TempB
scoreboard players operation @s TempC -= @s TempA
tellraw @a [{"text":"Delta "},{"score":{"name":"@s","objective":"TempC"}}]
#scoreboard players set @s[score_TempA_min=0,score_TempA=0,score_GM4_BBLoops_min=90] GM4_BBNState 6

scoreboard objectives remove TempA 
scoreboard objectives remove TempB 
scoreboard objectives remove TempC

I've been noticing that any time I run a testfor command that looks for data tags after a stats command, the result would sometimes be constantly wrong (usually resulting in 1)

Sometimes I can get around this by changing the scoreboards name (I did that here with Temp A, B, and C, they were originally another scoreboard) but I noticed the problem persists if you try to perform an operation on the scoreboard after acquiring the stats.
e.g. the code:

scoreboard players operation @s TempC = @s TempB
scoreboard players operation @s TempC -= @s TempA

was originally:

scoreboard players operation @s TempB -= @s TempA

TempC was not used, but this resulted in -1

it was then changed to:

scoreboard players operation @s TempC = @s TempB
scoreboard players operation @s TempC -= @s TempA

This resulted in 0

I then changed it to:

scoreboard players operation @s TempC = @s TempA

This resulted in 1.

based on this, it appears TempA and TempB are both set to 1 regardless of what the stats result is, however the result of this function is:
Dims # (Changes depending on how many people are online and in the overworld)
Sleeps # (Changes depending on how many people are in bed)
Delta 1 (always returns 1 even though it should return the difference between the two numbers)

before I switched scoreboards, both Dims and Sleeps returned 1 as well

This tells me that you can use the scoreboard in a selector and in tellraw, and it returns the true value, but using it in a scoreboard operation returns 1.

The function is located at gm4:modules/better_beds/state/5

Hopefully this is enough information to recreate the problem.
I know this is a problem because I've encountered this numerous times and have also seen many people encounter it as well. reloading or restarting the game doesn't fix this, nor does removing and re-adding the scoreboard objective.

Please thoroughly investigate, as this problem affects a lot of my functions and I would like for it to be resolved!

functions folder available upon request

Comments 4

You appear to be running this function from an entity, as you're setting the stats to @s. In that case, every line in the function is being executed as that entity and thus will affect the score sent to stats. Consider the following:

stats entity @s set SuccessCount @s success
testfor @a[r=5]
tellraw @a {"text":"There are this many nearby players:"}
tellraw @a {"score":{"name":"@s","objective":"success"}}

You might assume the success score is equal to the number of nearby players, but it's equal to one because the tellraw command succeeded.
To use stats effectively, you'll want to ensure you're only running the commands you need to as your target, or (my personal style), set the stats, run the command you need output from, then clear the stats immediately before attempting to read the value.
Hopefully this helps!

Ah, My apologies! The wiki's description of the function of this command isn't made inherently clear.
This isn't a bug then, just user error!

I'll find a real bug some day 😉

Yeah, /stats is a tricky one – lots of gotchas. Fortunately it's getting reworked to be much more streamlined in 1.13! 🙂

Have fun, keep it up.

Many thanks! Can't wait for the 1.13 syntax!

n00b_asaurus

(Unassigned)

Unconfirmed

/stats, scoreboard

Minecraft 1.12.1

Retrieved