1
Question: Need help writing score_ command
Problem with @s[score_Foo_min,score_Foo]
Hello Everyone,
I ran into a dilemma while writing a function to test the scoreboard. I need an efficient way to summon something only when "Foo" is NOT 2260. I wrote this command:
Of course, this doesn't work because the zombie would only be spawned if Foo was both lesser than AND greater than 2260, which is always impossible. I need some way (only involving commands, no redstone) to test if Foo is NOT a specific number.
This, I think, does accomplish it, but this isn't "efficient" when written over and over again:
Thanks in advance!
Hello Everyone,
I ran into a dilemma while writing a function to test the scoreboard. I need an efficient way to summon something only when "Foo" is NOT 2260. I wrote this command:
/execute @s[score_Foo_min=2261,score_Foo=2259] ~ ~ ~ /summon zombieOf course, this doesn't work because the zombie would only be spawned if Foo was both lesser than AND greater than 2260, which is always impossible. I need some way (only involving commands, no redstone) to test if Foo is NOT a specific number.
This, I think, does accomplish it, but this isn't "efficient" when written over and over again:
/scoreboard players tag @s remove NotEqu
/scoreboard players tag @s[score_Foo=2259] add NotEqu
/scoreboard players tag @s[score_Foo_min=2261] add NotEqu
/execute @s[tag=NotEqu] ~ ~ ~ /summon zombieThanks in advance!
4
I believe this should work: /execute @s[score_Foo=!2259]
The problem with score=!2259 is that "score_Foo" tests if Foo is less or equ, not just equ. That means that "=!" can't be applied to score_Foo
I tried it out:
This method is unusable because the same results also occurred when Foo was more or less than 2260
I tried it out:
/scoreboard objectives add Foo dummy
/scoreboard players set @s Foo 2260/testfor @s[score_Foo=!2259]
Entity @s[score_Foo=!2259] cannot be found
/testfor @s[score_Foo=!2261]
Entity @s[score_Foo=!2259] cannot be found
/testfor @s[score_Foo_min=!2259]
Found [@]
/testfor @s[score_Foo_min=!2261]
Found [@]This method is unusable because the same results also occurred when Foo was more or less than 2260
You're right. My bad, I use scoreboards sporadically but I keep forgetting that "score_Foo" doesn't mean "the value of score Foo" but "the maximum value of score Foo".
So I gave this some more thought (and testing this time!) and you're right, you'll need 2 tests. However, you can combine the two to make it a bit more efficient:
/scoreboard players tag @a[score_foo=50,score_foo_min=50] add equal
/execute @a[tag=!equal] ~ ~ ~ summon minecraft:zombie ~5 ~ ~
/scoreboard players tag @a remove equal
Optionally you could dump it into a function of its own, hope this can help a bit better than my previous comment :)
So I gave this some more thought (and testing this time!) and you're right, you'll need 2 tests. However, you can combine the two to make it a bit more efficient:
/scoreboard players tag @a[score_foo=50,score_foo_min=50] add equal
/execute @a[tag=!equal] ~ ~ ~ summon minecraft:zombie ~5 ~ ~
/scoreboard players tag @a remove equal
Optionally you could dump it into a function of its own, hope this can help a bit better than my previous comment :)
Excellent! I didn't think of inverting an AND test. I thought I'd have to write a much longer function to accomplish the same thing. Thanks!
