Enabling uninitialized trigger also sets score to 0
The bug
When you enable a trigger scoreboard objective for a player who has no score for it yet, the value is initialized to 0. This can cause problems if you use 0 as a value for an action.
The use for it might be to tell that a trigger objective was enabled, but in this case any scoreboard command changing the value before the test happens negates this use.
How to reproduce
- /scoreboard objectives add triggerObjective trigger
- /scoreboard players list @p
→ triggerObjective is not shown - /scoreboard players enable @p triggerObjective
- /scoreboard players list @p
→ triggerObjective is shown with a value of 0
Linked Issues
is duplicated by2
Created Issue:
Enabling trigger also sets score to 0
The bug
When you enable a trigger scoreboard objective it also sets the value to 0. This can cause problems if you use 0 as a value for an action.
The use for it might be to tell that a trigger objective was enabled, but in this case any scoreboard command changing the value before the test happens negates this use.
How to reproduce
- /scoreboard objectives add triggerObjective trigger
- /scoreboard players list @p
→ triggerObjective is not shown- /scoreboard players enable @p triggerObjective
- /scoreboard players list @p
→ triggerObjective is shown with a value of 0
relates to
The bug
When you enable a trigger scoreboard objective it also sets the value to 0. This can cause problems if you use 0 as a value for an action.
The use for it might be to tell that a trigger objective was enabled, but in this case any scoreboard command changing the value before the test happens negates this use.
How to reproduce
- /scoreboard objectives add triggerObjective trigger
- /scoreboard players list @p
→ triggerObjective is not shown- /scoreboard players enable @p triggerObjective
- /scoreboard players list @p
→ triggerObjective is shown with a value of 0
Enabling uninitialized trigger also sets score to 0
The bug
When you enable a trigger scoreboard objective
it also sets the valueto 0. This can cause problems if you use 0 as a value for an action.The use for it might be to tell that a trigger objective was enabled, but in this case any scoreboard command changing the value before the test happens negates this use.
How to reproduce
- /scoreboard objectives add triggerObjective trigger
- /scoreboard players list @p
→ triggerObjective is not shown- /scoreboard players enable @p triggerObjective
- /scoreboard players list @p
→ triggerObjective is shown with a value of 0The bug
When you enable a trigger scoreboard objective for a player who has no score for it yet, the value is initialized to 0. This can cause problems if you use 0 as a value for an action.
The use for it might be to tell that a trigger objective was enabled, but in this case any scoreboard command changing the value before the test happens negates this use.
How to reproduce
- /scoreboard objectives add triggerObjective trigger
- /scoreboard players list @p
→ triggerObjective is not shown- /scoreboard players enable @p triggerObjective
- /scoreboard players list @p
→ triggerObjective is shown with a value of 0
relates to
is duplicated by
is duplicated by
The bug
Enabling a /trigger for a player who has not yet been enabled before will set their score for the objective to 0, but does not display this on the sidebar scoreboard if the scoreboard is displaying when their trigger is enabled.
How to reproduce
- Add scoreboard objective
/scoreboard objectives add test trigger
- Set sidebar display
/scoreboard objectives setdisplay sidebar test
- Enable trigger
/scoreboard players enable @a test
- Notice score does not display on side bar but player has score of 0
/say @a[score_test_min=0]
- Remove scoreboard display
/scoreboard objectives setdisplay sidebar
- Put back display
/scoreboard objectives setdisplay sidebar test
- Notice score is now displaying as 0 for player
Code analysis
The problem is that the game creates a Score object when enabling a trigger for a player who has no score. As the score value inside the Score object is stored as an int, its default value is 0 (see MC-107049). Creating a Score object does not send a packet to the player. Changing this would cause the server to send a packet twice is you set a value for a player who had no Score object before, which could cause problems. A solution might be to store the score as an Integer. Then the default value would be null. Some methods would need to be changed then to test if the player has a Score object and the score value is not null instead of testing if the Score object is null.
A problem which should appear already is that using /scoreboard players reset also disables the trigger as it removes the Score object. With the suggested change a parameter like resetScore could be added which only sets the score of the Score object to null and by that remains the trigger state.
The problem is that the game creates a Score object when enabling a trigger for a player who has no score. As the score value inside the Score object is stored as an int, its default value is 0 (see MC-107049). Creating a Score object does not send a packet to the player. Changing this would cause the server to send a packet twice is you set a value for a player who had no Score object before, which could cause problems. A solution might be to store the score as an Integer. Then the default value would be null. Some methods would need to be changed then to test if the player has a Score object and the score value is not null instead of testing if the Score object is null.
A problem which should appear already is that using /scoreboard players reset also disables the trigger as it removes the Score object. With the suggested change a parameter like resetScore could be added which only sets the score of the Score object to null and by that remains the trigger state.
Thank you for your report!
We're tracking this issue in MC-107049, so this ticket is being resolved and linked as a duplicate.
If you would like to add a vote and any extra information to the main ticket it would be appreciated.
If you haven't already, you might like to make use of the search feature to see if the issue has already been mentioned.
Quick Links:
📓 Bug Tracker Guidelines – 💬 Community Support – 📧 Mojang Support
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 Game Wiki
– I am a bot. This action was performed automatically! The ticket was resolved by one of our moderators, and I left this message to give more information to you.
Might be invalid or works by design.
The score objective has a field for whether it is locked or not. If a player has no score, he also does not have a score objective. A state in which the player has a score objective but no score currently sadly does not exist.
Relates to
MC-79255Fixed in 1.11.2 at the latest.
Misunderstood the report. Not fixed, but WAI per the fix of
MC-79255....leaving open for an explicit dev decision.
There is no such thing as an uninitialized but enabled score. If a score doesn't exist, it can't have properties.