2

How do I detect a change in Scoreboard values?

AndCastle's Avatar AndCastle7/24/22 7:25 pm
8/9/2022 5:26 pm
Radon8472's Avatar Radon8472
Hi. I'm new to the scoreboard command and I was wondering how I could detect a single change in a scoreboard, so I can execute a command afterwards. I'm making a map with right click detection and relative teleports, and I need to know how I could detect one increase and execute one command at a time.
Posted by AndCastle's Avatar
AndCastle
Level 3 : Apprentice Explorer
3

Create an account or sign in to comment.

4

Radon8472
08/09/2022 5:26 pm
Level 6 : Apprentice Miner
Radon8472's Avatar
I`m not sure if that is the best way, but I would:

  1. copy the "current" score in a dummy score value
  2. then add a tick function (or e repeating commandblock) what compares if the dummy score and the real score are equal
  3. if they are NOT equal, the score has changed
  4. in that case execute yout command and, copy the real score again into the dummyscore
Thats all, I hope it helpes
1
Skelun
07/24/2022 7:34 pm
Level 44 : Master Artist
Skelun's Avatar
You have to use another scoreboard to track the previous one.



Example:

scoreboard objective add Points dummy
scoreboard objective add PointsCheck dummy
execute as @a if score @s PointsCheck = @s Points run ...
3
AndCastle
07/24/2022 7:41 pm
Level 3 : Apprentice Explorer
AndCastle's Avatar
Could you elaborate a bit more? I'm a tad bit stuck.
1
Skelun
07/24/2022 8:41 pm
Level 44 : Master Artist
Skelun's Avatar
Lets suppose you're trying to know when a player has caught 10 fish.



First you setup two scoreboards:

scoreboard objectives add FishGoal dummy

scoreboard objectives add FishCaught minecraft.custom:minecraft.fish_caught



The first scoreboard is empty (dummy);

And the second will track how many fish you caught while fishing.



To know if a player has caught 10 fish, you have to compare his FishCaught score with something.



This something can be another scoreboard that you manually set up. In this case FishGoal.



So we set our goal number in the dummy scoreboard, as follows:

execute as @a run scoreboard players set @s FishGoal 10

Execute as Any Player(@a) the following (run) set this dummy scoreboard name FishGoal for the current player (@s) as 10.



Then you compare both scoreboards to check if the player has reach the goal:

execute as @a if score @s FishCaught = @s FishGoal run tellraw @s {"Text":"You caught 10 fish!"}

BUT, to preventing this from looping infinitely while our FishCount is the same as our goal, we can give the player an advancement or a tag, and check if the player has this any of this, before we run our code.



execute as @a[tag=!Fisherman] if score @s FishCaught = @s FishGoal run say You caught 10 fish!execute as Any Player (@a) that has no tag called Fisherman ([tag=!Fisherman] – The "!" inverts the "=") if the score FishCaught is the same FishGoal run this.


execute as @a[tag=!Fisherman] if score @s FishCaught = @s FishGoal run tag @s add Fishermanthe same as before, but now we add the tag to prevent the infinite loop.
2
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome