Is that Logic There? Or are You Just Glad to See Me?

Rate this Entry
Well, as promised, we are doing a little detour into the realm of the known. Yes, my little sackpeople, we are going to go over the basics of logic, why it is important, and why everyone seems to be doing it these days.

I mean, it MUST be important if everyone is doing it, right?

So lets start off with a little problem.

The Problem

Hi, I'm Joe Sackperson and I'm building my very own, wow, gosh, SUPER level that everyone is going to love and and I'll get a billion zillion hearts for.

Except I have this ONE itsy bitsy, teeny, tiny, "oh, it's nothing", problem -- I have a puzzle that I can't figure out how to do the logic for (and if you think THAT is grammatically questionable, you haven't been reading these blogs!).

The Problem: I have two slots. If someone puts key A in Slot A OR key B in Slot B then I want to give them BUNCHES of prize bubbles (HOORAY!). BUT if they put BOTH key A in slot A AND key B in Slot B then I want a large brick to fall on them.

Didn't say it would be a good puzzle.

The OR Gate

Looking back at our "Problem" we can pick out some key words (you might have noticed that they had BOLD PRINT). This is your first hint what you need.

The OR gate is a wonderful little device. When N00BS complain "why can't I hook up more than one wire to a piston?" well, guess what? With an OR gate you can!

Here is the logic diagram for an OR gate:

    A   B   Output
    0   0      0
    0   1      1
    1   0      1
    1   1      1
Imagine that A and B are switch inputs. Output goes to your piston. Now, if you turn on A, the piston will extend. If you turn on B, the piston will extend (turn on).

Wow! That makes things a lot easier!

Look at our problem. See where it has "If they put key A in Slot A OR key B in Slot B then I want to give them BUNCHES of prize bubbles"? To do this in LBP hardware we would have something like the following:

If Switch A or Switch B is turned on, then the prize emitter is turned on. If both are turned off, then the prize emitter is turned off.

The key thing to remember about the OR gate is that you use it when you want one or more things to turn something on.

Great! We are almost halfway there, right?

The AND Gate

Looking back at our problem we notice that we also have ANOTHER word in bold (convenient that they do that, eh?). That is our hint that we PROBABLY want to use an AND gate.

AND gates are picky little devices. They won't output a signal until ALL inputs have a signal. Much like a good driver won't start the car until all the doors are closed, seat belts are buckled, and someone has a map just in case the driver gets lost.

Here is the logic diagram for an AND gate:

    A   B   Output
    0   0      0
    0   1      0
    1   0      0
    1   1      1
Notice how NOTHING is output until all inputs have a one? That's the brilliance of an AND gate.

Back to our problem, remember we want to drop a giant brick on the unsuspecting sack person's head if key A is in slot A and key B is in slot B? This is how it would look with LBP hardware:

So beware, you turn A on AND B on and that brick is falling on your head!

Okay, Let's Solve the Problem

Great, now we have the two pieces of the puzzle that we need.

  1. They get prize bubbles if they put either key A OR key B in the appropriate slot
  2. Or if they put BOTH keys in they get a brick on the noggin'

So much for "E for Everyone", eh?

But, lets move on and draw this up as a proper little "circuit".

A True Logic Circuit

So now we have the basic pieces all we have to do is jam 'em together, right? Well, actually for this simple case, yes.

There we are: our first bit of logic that does something ... interesting.

Now some of you will go "Hey, if A is turned on then B is turned on, you will get prize bubbles and then get squished!"

Oh, dear, our first bug!

Fortunately, we can solve this by making sure our gates move slowly (a second or two). "But surely that's a hack?!?!" you might wonder. It all depends. Personally, I would argue that a small delay is cheaper in thermo than slapping on more logic.

So there you go: AND and OR gates!

What About XOR?

Ah, my friend, that is the most ignored gate of all. The XOR is a WONDERFUL device. Imagine you want something to move left to right when a button isn't pressed, but right to left when the button IS pressed. This is easy to do with an XOR (exclusive or) gate.

Here is the logic diagram for an XOR gate:

    A   B   Output
    0   0      0
    0   1      1
    1   0      1
    1   1      0
Notice that the output is one IF and ONLY IF there is only ONE input set high. Otherwise it is zero.

Now here is the cool part. Imagine that A is a switch and B is the output from some device. When A is zero and B is zero, the output is zero. BUT if A is a 1 and B is zero, then the output is a 1. You can now change the direction of your signal using a pushbutton!

How cool is that?

But let's take another example: imagine a puzzle where if A is turned on the platform explodes. If B is turned on, the platform explodes. BUT if A AND B are turned on simultaneously, the platform does nothing. You can't do this with an AND gate (notice: NO BOLDFACE).

Here would be the diagram:

Notice that the logic diagram says the bomb won't go off if A and B remain where they are OR if A and B are removed at the same time. If only ONE is removed, KABOOOM!!! And sackboy turns into glowing red bits (hey, how is that "E for Everyone?!?").

We are Done?!?!

Yup. That's a very short tutorial.

Print it off. Read it multiple times. Put it under your pillow at night (although it won't help and must make it hard to sleep).

EVENTUALLY we we move on to the monostable multivibrator (oooooooo, it sounds so dirty!). Or as engineers call them, one-shots.

But I think it would be nice to review the RS Latch and how it can be used in place of the P-switch or permanent switch to give your logic a nice, resettable feel. Always good when sack boy bites the dust!

And if he plays in MY little scenario as above, he is going to get SQUISHED or KABOOM'ed!

Updated 05-05-2009 at 08:32 PM by feloneouscat



  1. RockSauron's Avatar
    Intriguing... you should consider writing a logic tutorial in the tutorial sub forum :O
  2. feloneouscat's Avatar
    I will continue with a blog tutorial (actually all of these are leading up to the GRAND TUTORIAL).

    I just want to get everything out of way first.
  3. Burnvictim42's Avatar
    nice tutorials This is a great explanation of what logic gates are/and do for the uninitiated.
  4. feloneouscat's Avatar
    Thanks! Fjonan asked that I do a quick review before I head into deeper territory (which I plan on doing with this blog).
  5. Astrosimi's Avatar
    Oh wow. I bookmarked this. Very simple and user-friendly tutorial.
  6. Fjonan's Avatar
    Wow the XOR example would be perfect for a 2 player level, or even more.

    Genious! Keep on writing!

    Only problem with XOR ... can't think of a way how to make it in LBP right now ... but I did not have my first coffee yet.
  7. feloneouscat's Avatar
    can't think of a way how to make (an XOR) in LBP right now

    I covered that in my previous blog titled "Wobbly Logic". Pretty easy to do with a wobble bolt or a piston.
  8. AJnKnox's Avatar
    You are too smrt! (I mean smArt) Can you hear Homer Simpson?

    Great stuff, an awesome resource! keep up the good work..and continue as I need the next lesson!
  9. feloneouscat's Avatar
    I'm looking forward to writing the next lesson! I'm hopping up and down even as I type because I have to work (stupid work)... I'd rather write the next lesson (stupid work).
  10. Morgana25's Avatar
    WOW - I think I understood that. There's hope for me yet!

    Thanks feloneouscat!
  11. feloneouscat's Avatar
    Excellent! I hope everyone who reads this understands it...

    BTW, I esp. like my description of the AND gate (laughs). But Mrs. Cat says I laugh at my own jokes a lot...
  12. Ragfell's Avatar
    I don't understand. lol.
  13. Raiden's Avatar
    so how do i actually create an OR and AND gate