-3

This question already has an answer here:

I'm trying to make a door that searches a player's inventory for a golden nugget named "Golden Leaf". I have all of the redstone working, but for some reason the command block that tests for the item stays active, so I have a different command block hooked up to replace it and deactivate it. However, it wont work. This is the command I'm currently using:

/setblock -9456 83 10214 command_block 0 replace {Command:"/testfor @p {Inventory:[{id:"minecraft:gold_nugget",tag:{display:{Name:"Golden Leaf"}}}]}"}

And it keeps saying "Invalid character at "m" in minecraft. I changed it and took out the 'minecraft' part but it still won't work. What is wrong?

marked as duplicate by bearb001, Gigazelle, Tim S., Schism, Ivo Coumans Jul 12 at 6:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You're asking this because you have a problem with the workaround for another problem. Then why don't you ask about your first problem instead? Also, you shouldn't need to use redstone for command blocks. It slows everything down and makes it more complicated than it needs to be. – Fabian Röling Mar 24 '18 at 10:33
  • I agree with Fabian. This sounds like quite a complicated workaround that probably doesn't have to be used. You should post another question which describes what you are trying to do and demonstrates your problem. You will probably get a simpler, more efficient solution. Simple leaves less room for error. – IronAnvil Mar 26 '18 at 13:47
2

The problem is because you are trying to put quotes inside of eachother and the game doesn't know how to handle it. What you have to do is put backslashes before the quotes inside so it knows to use them in the command instead of as the main quote

/setblock -9456 83 10214 command_block 0 replace {Command:"/testfor @p {Inventory:[{id:\"minecraft:gold_nugget\",tag:{display:{Name:\"Golden Leaf\"}}}]}"}

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