I need help to fix this command. I have tried but it does not work in 1.9 The command is testfor @a[r=3,score_GameTokens_min=5] > give @p cooked_porkchop 3 | /scoreboard players remove @p[r=3] GameTokens 5. When i try it says Invalid stuff and expected { as first char. If you can fix this I would greatly appriciate it. I already tried changing it a few times and I searched online but there was none so I had to make a new thread.

  • 2
    I'm curious. What exactly made you think that you could chain commands using > and |? Minecraft commands are not bash.
    – MrLemon
    Mar 11 '16 at 9:18
  • 1
    @MrLemon I so dearly wish that would work. :P Mar 11 '16 at 9:31

You'll likely want to use an impulse block with the following command (thanks @Skylinerw for reducing the command!):

/give @p[r=3,score_GameTokens_min=5] cooked_porkchop 3

Followed by an always active unconditional chaining command block:

/scoreboard players remove @p[score_GameTokens_min=5] GameTokens 5

You'll want to make sure that @p always targets the right player - integrating a temporary dummy objective to trace the player who's buying might be beneficial here, if you need help with that, ask another question on the main site.

  • 1
    To clear up misconception: /testfor works fine and can potentially do less work than /scoreboard. By using /scoreboard like that, it has to be processed for every target obtained in that area as well as check their score. Using /testfor allows you to reduce the number of times a command is processed due to the selector itself (since the score check is done in the selector): /testfor @p[r=3,score_GameTokens_min=5]. If you have an issue with a command, I recommend asking a question about it first, as it does work correctly. Realistically though, the first command isn't even needed.
    – Skylinerw
    Mar 11 '16 at 15:43
  • @Skylinerw In the 1.9 versions I tried (1.9, 1.9.1-pre1 through 3), testfor was consistently not passing the correct condition value (either it was true or false, but incorrectly so) to a conditional chain block. I'll integrate your suggestions into my answer and see if anyone else is having my problem (could've been on my end, I'm not sure). Mar 11 '16 at 18:08
  • If you were using the r parameter, is was changed a handful of times to clear up issues and be more accurate (for example, r=0 no longer selects a whole blockspace). Nothing has changed concerning /testfor itself, and any problems as a result of a selector and SuccessCount of a command block would occur regardless of command used. There were still some issues where executed command blocks were forced to wait until the next tick to activate, resulting in unexpected outcomes from command chains, which was "resolved" in 1.9.1 pre-releases (1000 command blocks per tick increased to 65536).
    – Skylinerw
    Mar 11 '16 at 18:16
  • ¯\_(ツ)_/¯ It's likely that I made a mistake in my command, now that I'm looking at it - I looked again and it seems to be working just fine now. :D @Skylinerw The answer has been fixed now, though. Thanks! Mar 11 '16 at 18:19

Try using a comparator.

First command block:

/testfor @a[r=3,score_GameTokens_min=5]

Then use a comparator followed by a repeater going to 2 command blocks:

/give @p cooked_porkchop 5

/scoreboard players remove @p GameTokens 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.