PDA

View Full Version : Code Sequence



Grim
02-20-2011, 04:16 PM
I didn't find this anywhere else when I myself couldn't figure it out, but now that I know how and still don't see a tutorial I figure I might as well make one.

This a simplistic yet very accurate way to create a code sequence such as the famous Konami Code, but it can also apply to other inputs besides buttons:

1. Make an XOR gate with an input for each output that will reset the sequence if triggered at the wrong time. Keep in mind that these do not need to be part of the sequence in order to reset it, which is why I linked every button and joystick on the controllinator to the XOR gate in the figure below. Now make a counter with a target count of 1 and connect its output to its own reset input. Connect the XOR gate to the counter's main input. If your XOR gate has any inputs that can be negative (such as down or left on the joysticks/d-pad), you'll want to run it through two NOT gates first in order to get the absolute value as seen in the figure below. Without those NOT gates a negative input would not be able to trigger the counter. You should end up with an output that activates momentarily when any of the buttons are pressed:
http://www.orangemarble.net/lbp/1.jpg

2. Place a selector with the port number equal to the amount of inputs in your sequence plus one, and link the counter from step 1 to its first input. Place an AND gate for each input in the sequence and link each output on the selector to each AND gate in order from #1 to whichever output comes second-to-last. Now connect each AND gate's output back to the selector so that the AND gate taking selector output #1 loops back to selector input #2, #2 to #3, etc. I recommend color coding the AND gates to make the sequence a bit more readable. This is what it looks like with 4 inputs:
http://www.orangemarble.net/lbp/2.jpg

3. Now simply connect each button to the AND gates going in sequence. In my example I use Up, Down, Triangle, and Cross in that order, which requires the use of a direction splitter. Hook the last output on the selector to whatever you want to activate when the code is completed. You now have a fully functional code sequence:
http://www.orangemarble.net/lbp/3.jpg

4. You may notice that you can still cheat the code sequence by holding one button down that isn't in the sequence and randomly mashing on the rest. This is because of a stupid oversight I noticed only after I took my screenshots, but you can fix it simply by moving the AND gates into a microchip and linking the XOR gate's output to it:
http://www.orangemarble.net/lbp/6.jpg

5. (optional) If you want to make it easier to tell which AND gate has which button assigned to it, you can use microchips instead of AND gates altogether. Have the selector turn on the microchip which has a circuit node for the next button passing through it. This functions very much the same as an AND gate but the wires should be easier to read while their respective microchip is open. You can also reverse this and have the microchip activate when the button is pressed, then pass the selector's output through it instead. This can save you some microchips whenever the same button is used multiple times in the sequence, but it can be a little more confusing since there won't be a colored microchip for those parts of the sequence anymore. Note that this example can still be cheated without being inside the microchip from step 4:
http://www.orangemarble.net/lbp/4.jpg

6. Any buttons that appear twice in a row should first be run through a counter like the one in step 1. Here is what it'd look like if Down in the sequence was replaced with another instance of Up:
http://www.orangemarble.net/lbp/5.jpg

That should leave you with a mostly perfect code sequence using one button at a time. Let me know if there's any amendments I should make, or if I'm overlooking a far better way to do it. :p

midnight_heist
02-20-2011, 04:32 PM
Cool, been wanting to try a tutorial for this. Will try it out tonight and let you know how I go.
Thanks for including pics btw.

What do you need to do if you want to use the analog stick instead of the d-pad?
(as I don't like disabling popit)

Grim
02-20-2011, 04:46 PM
What do you need to do if you want to use the analog stick instead of the d-pad?
(as I don't like disabling popit)

Same thing you'd do for the d-pad, except you may need to take some extra measures to help prevent one direction from accidentally nudging one of its two perpendicular ones. The first thing that comes to mind is a battery on a sequencer that makes the counter in step 1 only activate when the analog signal from the second NOT gate is more than 10-20% or so.

flamesterart
02-21-2011, 02:33 AM
We could use this to make a level for people to use to send project levels between each other without anyone getting it that isn't supposed to! I might try that.... thanks for the tutorial. I am going to use this.

midnight_heist
02-21-2011, 04:05 AM
Ok, had a go.
All good until I tried step 4 (prevent cheating).
The selector is stuck on the first output, and won't move no matter which button I press (including the code).
I'm guessing I did it wrong somehow.

Bloblblobl
02-21-2011, 04:47 AM
In step one, I think you can simply use an inverted not gate (yes, you can invert them) instead of two normal not gates

Antikris
02-21-2011, 01:20 PM
I see Booxely already found this tutorial! He and me were messing around a bit the other night trying to get something up.

I gave up very early. :)

By the way, what I am curious about, is the basics behind this the fact that both an output from the XOR gate and a correct user input are received by the Selector and the Selector gives priority to the highest input channel number (meaning the correct button overrides the XOR gate that resets the Selector on ALL user input)?

If so, why using a XOR gate? What does a XOR gate with more than two inputs do exactly? Would an OR gate not be enough here?

Grim
02-21-2011, 05:55 PM
In step one, I think you can simply use an inverted not gate (yes, you can invert them) instead of two normal not gates
A simple repeater like that will still pass negative values through. I'm not sure if that's a bug or what, but that's the way it is.


By the way, what I am curious about, is the basics behind this the fact that both an output from the XOR gate and a correct user input are received by the Selector and the Selector gives priority to the highest input channel number (meaning the correct button overrides the XOR gate that resets the Selector on ALL user input)?

If so, why using a XOR gate? What does a XOR gate with more than two inputs do exactly? Would an OR gate not be enough here?Yes, this works because selectors give priority to higher ports. The circuit waits for any of the inputs to turn on and attempts to reset the selector, but gets overridden by a higher port if that input was the correct one.

The XOR gate turns on only when exactly one button is being pressed, so it won't allow you to cheat by holding down every button at once like an OR gate would.

Edit:

Ok, had a go.
All good until I tried step 4 (prevent cheating).
The selector is stuck on the first output, and won't move no matter which button I press (including the code).
I'm guessing I did it wrong somehow.Can you get me a screenshot of your setup?

midnight_heist
02-22-2011, 03:03 AM
http://i1.lbp.me/img/ft/2c11661467539cb02ba2a7a8264ad6ab546b9817.jpg
Here ya go.
I double checked the steps.
It's the konami code.

wait wtf
02-24-2011, 01:31 AM
what about letter codes?

Grim
02-27-2011, 08:50 AM
Very delayed reply but...

http://i1.lbp.me/img/ft/2c11661467539cb02ba2a7a8264ad6ab546b9817.jpg
Here ya go.
I double checked the steps.
It's the konami code.
It's probably because you have the wires from the splitter running through the microchip with the AND gates instead of directly to the two counters, creating either a delay or cutoff of some sort. I'm not sure if that's the problem because I see no reason for it to happen, but it looks like the only thing you did differently. I also have no clue how you're using both up/down and left/right in the sequence without more than one splitter.

It's unnecessary to have the splitter's two outputs connected to the XOR gate separately when you can just link the single up/down output to them. I doubt that's causing any problems though.