1

Question: Need help writing score_ command

Thunder_Clap_0 12/31/17 2:48 pm
244
1/1/2018 8:45 pm
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:

/execute @s[score_Foo_min=2261,score_Foo=2259] ~ ~ ~ /summon zombie
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:

/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 zombie
Thanks in advance!
Posted by
Thunder_Clap_0
Level 1 : New Crafter
2

  Have something to say?

JoinSign in

4

ShelLuser
12/31/2017 7:11 pm
Level 61 : High Grandmaster System
I believe this should work: /execute @s[score_Foo=!2259]
1
Thunder_Clap_0
12/31/2017 8:29 pm
Level 1 : New Crafter
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:

/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
1
ShelLuser
01/01/2018 6:52 am
Level 61 : High Grandmaster System
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 :)
2
Thunder_Clap_0
01/01/2018 8:45 pm
Level 1 : New Crafter
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!
1

Welcome