1

Building An "If/Then/Else" Statement with Redstone

ToadieOdie's Avatar ToadieOdie11/19/15 7:28 pm
1 emeralds 4.9k 3
11/19/2015 9:11 pm
ToadieOdie's Avatar ToadieOdie
Okay, my coding experience is pretty limited - mostly right down to HTML for webpages, and building bots with the now broken Spellcast for FFXI back in its hay day which used XML. So basically it would allow you to swap out gear sets for a different set of gear during combat automatically based on whatever conditions you've placed using the if/then/else format.

Basically:

IF this is TRUE
THEN do this
ELSE do this instead

Now I know how to set up with command blocks and comparators an IF/THEN statement that works, but I would like to also add an "ELSE" to that. So let's say whatever it was that I tested for came out false, it did something else.

Like for example, I would like an NPC named Farmer Brown (random lame name, I know) ask you to bring him 64 wheat whenever you talk to him as a repeatable quest. Right now I can set up as two separate buttons with two separate lines of command blocks to tell you what he wants and then collect from you the said 64 wheat. What I would like to do is to have both sets of command blocks connected to 1 button so it checks to see if you have at least 64 wheat, and if you do have that many he takes them and gives you the reward - but if you only have 63 wheat or less, he tells you to bring you the wheat.

In other words:

IF player has at least 64 wheat is TRUE
THEN remove 64 wheat from inventory and give reward
ELSE tell player to bring 64 wheat

How do I make that happen? Placing a redstone torch on the side of the command block won't work because it's only active when the button isn't pressed, which the player needs to do to speak to the NPC. The "Count" value in the data tag for the player's inventory is an AT LEAST value, so unless I am missing something I have no way to check for a maximum count in the player's inventory. Because I want the NPC to tell the player to get the wheat even if the player only has some of the wheat, not just when the player is empty handed, so setting Count to 0b will only quasi work either.
Posted by ToadieOdie's Avatar
ToadieOdie
Level 54 : Grandmaster Goblin
182

Create an account or sign in to comment.

3

1
11/19/2015 9:11 pm
Level 54 : Grandmaster Goblin
ToadieOdie
ToadieOdie's Avatar
Fixed it and got it working. I took a screenshot of my set up and edited it with some explanations for anyone else that might have the same question.

Click to reveal


Edit: Seems the post cuts off the image. It can be found here:

http://i81.photobucket.com/albums/j211/toadie-odie/Minecraft/IfElseExampleCircuit_zpsiawohkxb.png
1
11/19/2015 8:32 pm
Level 54 : Grandmaster Goblin
ToadieOdie
ToadieOdie's Avatar
Nope, the command block that's supposed to false result activates every time in that image example. Not sure what I'm doing wrong.
1
11/19/2015 8:20 pm
Level 54 : Grandmaster Goblin
ToadieOdie
ToadieOdie's Avatar
Nevermind, found what I was looking for here:

http://imgur.com/a/VtjFf
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome