2
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.
Create an account or sign in to comment.
4
I`m not sure if that is the best way, but I would:
- copy the "current" score in a dummy score value
- then add a tick function (or e repeating commandblock) what compares if the dummy score and the real score are equal
- if they are NOT equal, the score has changed
- in that case execute yout command and, copy the real score again into the dummyscore
You have to use another scoreboard to track the previous one.
Example:
Example:
scoreboard objective add Points dummy
scoreboard objective add PointsCheck dummy
execute as @a if score @s PointsCheck = @s Points run ...
Could you elaborate a bit more? I'm a tad bit stuck.
Lets suppose you're trying to know when a player has caught 10 fish.
First you setup two scoreboards:
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 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:
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.
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 Fisherman
the same as before, but now we add the tag to prevent the infinite loop.