I'm trying to make a map where I need to make it that when you press a button, and something happens, and when you press it again, something different happens.
-
So... you want when you press a button it outputs a signal, but when you press it again, it outputs another signal?– TheVoidChaosCommented Oct 23, 2016 at 16:16
-
@TheVoidChaos I think so.– user143228Commented Oct 23, 2016 at 17:28
-
@RudolfL.Jelínek Ok, will answer soon, just need confirmation from OP.– TheVoidChaosCommented Oct 23, 2016 at 17:56
3 Answers
Here is a redstone solution, one-use only:
Additional info:
the 2 uppermost repeater at output 2 can let signal pass only if the repeater under it is off, that is, if the torch is destroyed
an AND gate is a device where both inputs to it must be powered for the output to be powered
to reset it, re-place the torch in the middle
What it does (i tried to explain as "noob-friendly" as possible):
When the button is first pressed, the AND gate will power the 1st output for 0.6 seconds, then the redstone torch in the middle will be destroyed, so the 1st output can't pe powered anymore, and the 2nd will get unblocked.
When it's pressed again, the AND gate won't power, because the Redstone torch is missing. The 2nd output will get powered, because the repeater going from the button is unblocked and can let signal pass.
The 2nd output will get powered every time after that.
TL;DR: First press powers the right lamp, second the left.
-
Ok, This I SO Confusing– user166129Commented Oct 25, 2016 at 20:40
-
@Player thanks for coming back and accepting this answer. By doing so you help future visitors know the answer that helped you. Commented Nov 26, 2016 at 16:40
-
1What is your minecraft username? I'm thinking of making a video of this.– user166129Commented Nov 26, 2016 at 16:45
-
1@Player RudolfJelinCZ :) Thanks! Edit: Also thanks for the edit! Commented Nov 26, 2016 at 16:49
A great way to make a button system as you've said is to use a scoreboard objective.
First of all, make the scoreboard objective
Run this command in chat to create a dummy scoreboard objective named Output:
/scoreboard objectives add Output dummy
Next, determine the input source
To do this, place a standard impulse command block after your output and write this into it:
scoreboard players add @a Output 1
After that, set up the output system
Next place multiple always active repeating command blocks next to each other in a row, the length being how many different outputs you want (in this case 2). However, this will only work in single-player. If you want a multiplayer system, separate the repeating command blocks
(It does not matter where in the world you place these repeating command blocks, but putting them near your input will make it simpler to understand what it's doing.)
In the first command block, write this command:
testfor @a[score_Output=1,score_Output_min=1]
In the second, write this:
testfor @a[score_Output=2,score_Output_min=2]
(If you would like more, add more in the row and change the testfor score in ascending order)
Place comparators facing out of these repeating command blocks.
Finally, determine the output type
If you want this system to output to commands, simply place a solid block after the comparators and then your impulse command block after that block. If you want other commands to run as well, you will need to create a chain of always active chain command blocks after the impulse block.
If you want a redstone output, place redstone dust after the comparators and redstone repeaters facing out of those (changing the direction of one if required).
I have another solution that does not require command blocks and is not a one time use.
It has three outputs but you can connect first output to nothing. In that case, you press the button once and output 1 goes high, press it again and output 2 goes high. Press it a third time and output 0 goes high again.
Image shows the three states it can be in.
It is a dropper, hopper train. Dropper faces into a hopper which faces into the next dropper(green arrows in image indicate direction). Place an item in one dropper and redstone dust on top of all droppers and hoppers. When that redstone dust is powered the item will move to the next dropper in the line and the comparator on that dropper will output.
Simple to build. It can be expanded to have more outputs(more button clicks) by adding more hoppers and droppers in the train. You only need comparators on droppers that you want to output. In this case, you don't need comparator labeled Output 0.
I use this circuit with observer monitoring block in front of piston to "count" the pulses out of the observer as a way to ignore the two pulses created by the piston extending and retracting. (Auto pumpkin/melon farms)