PDA

View Full Version : Tutorial 2.3 - Optimizing Your Logic



Logic Pack
11-05-2009, 02:01 AM
Tutorial 2.3 - Optimizing Your Logic
By ConfusedCartman (http://www.lbpcentral.com/forums/member.php?u=118)

Optimizing your logic networks is essential to keeping the thermometer low. It's very easy to add unnecessary logic, but it's a lot harder to determine which pieces of logic are actually unnecessary once you have all the pieces in place. We're going to present three potential networks that all accomplish the same basic goal, then we'll discuss each piece of logic in each network and explain why that piece of logic is necessary (or not) to the overall network.



http://www.lbpcentral.com/images/logic_pack/tutorials/2-3/2-3%20%281%29.jpg

We're going to be using a basic drawbridge to build upon. The construction of this setpiece isn't important here, so we won't be going over it. We don't suggest building this yourself either - you'll learn what we're trying to teach by simply reading through the tutorial itself. As always, we have a companion level up under our PSN (LogicPack) if you want to copy it to your moon and pick it apart yourself.



http://www.lbpcentral.com/images/logic_pack/tutorials/2-3/2-3%20%282%29.jpg

So, what if you wanted to ensure the drawbridge would lower when Sackboy got close to it, regardless of which side he was on? Here's an initial solution. On the left, we have a Sackboy Tracker with a magnetic key attached to it in order to determine and convey Sackboy's location. On the right, a matching magnetic key switch. It's positioned sideways, facing the gap, its angle is set to 180 degrees, and its radius is big enough to detect the magnetic key when it comes close to the edge. When the magnetic key switch is activated, it causes the drawbridge to lower. Seems like a sound solution, right?

Actually, while it's fairly clever, it's over-complicated. Over-complication is one of the most common problems with logic networks. A solution might seem reliable, but too many parts isn't always a good thing. Over-complication causes the level to overheat faster, because you're using more logic than necessary for a specific task. If you know how to simplify your logic down so that it's only as complicated as necessary, you'll be able to save yourself a good chunk of thermometer that can then be applied towards other things in your level. So, what's the efficient solution?



http://www.lbpcentral.com/images/logic_pack/tutorials/2-3/2-3%20%283%29.jpg

This is. A simple sensor switch, set to directional and hooked to the drawbridge. Its radius is large enough to reach the other side, so the drawbridge will lower as Sackboy approaches the gap. This doesn't use any of our logic, but it still manages to accomplish the task we set out to accomplish: the drawbridge will always lower for Sackboy, allowing him to cross both ways.



http://www.lbpcentral.com/images/logic_pack/tutorials/2-3/2-3%20%284%29.jpg

Here, we've decided that we want the drawbridge to lower when Sackboy gets near it, but once it is lowered, we also want it to remain open whether or not Sackboy is close to it. The above solution is another example of over-complication. The sensor switch on the left is set to directional and hooked to both pistons on the AND switch. The AND switch is set to directional and hooked to the piston on the Switcher. The Switcher is set to directional and hooked to the permanent switch. The permanent switch is set to directional and hooked to the drawbridge. Although it sounds complicated, it does do the job.

Now, I know what you're thinking: it's obviously over-complicated, to the point that you wouldn't make this mistake in the first place. However, what about in a logic network two times the size of the above network? How about five times as large? Ten? The point I'm trying to make is, the larger your logic network, the harder it is to determine if it's over-complicated or not. Something like this could easily go unnoticed because it would be surrounded by lots of other logic and wiring. That's why it's important to plan out your logic networks in your head beforehand - even if you don't get it right the first time, at least you have a plan that you can work from, minimizing possible over-complication.



http://www.lbpcentral.com/images/logic_pack/tutorials/2-3/2-3%20%285%29.jpg

This is an efficient solution: a simple Permanent Switch. The drawbridge will open when Sackboy nears the gap, and once it opens, it will remain open regardless of Sackboy's position.



http://www.lbpcentral.com/images/logic_pack/tutorials/2-3/2-3%20%286%29.jpg

Now, what if we wanted the drawbridge to open when Sackboy gets close to the edge, but close behind him so that he cannot go back where he came? Above is a possible solution: a sensor switch connected to a Quick-Reset Timer (so that Sackboy always has the same amount of time to cross, even if he recently activated the timer), which is then connected to the drawbridge. As Sackboy activates it, he has a preset amount of time to cross, after which the drawbridge will close behind him. So, this seems like a fine solution - why is it wrong?

To put it simply, it isn't technically "wrong". If you desperately preferred a timer, then this solution is about as good as it gets. However, let's review the goal: we want the drawbridge to open when Sackboy gets close to the edge, but close behind him so that he cannot return the way he came. In this case, the argument of "optimized vs. non-optimized" doesn't apply to the complication of the logic network, but the way it solves the problem. To those that cross slowly, using a timer will seem like bad design - they will wonder why the drawbridge began to raise while they were still on it. We need to come up with a different solution, one that will only cause the drawbridge to raise once Sackboy is safely on the other side. So, what should we use?



http://www.lbpcentral.com/images/logic_pack/tutorials/2-3/2-3%20%287%29.jpg

Our Set-Reset switch is perfect for this. There's one sensor switch on each side of the drawbridge, and each sensor switch is hooked to one of the winches on the Set-Reset switch. When Sackboy activates the left sensor switch, the drawbridge will lower. When he activates the right sensor switch, the drawbridge will raise. This solution will only function reliably with one Sackperson, but with a little ingenuity it can be modified so that it will work reliably with 1-4 Sacks. We won't go over that solution here as it doesn't really pertain to the tutorial, but flex your newfound Logic muscles and see if you can come up with a multi-Sack solution. As always, the companion level is up under our PSN (LogicPack) if you want to copy it to your moon and work on it there.

There isn't much else to logic optimization. Generally, as long as you're simplifying your logic networks as much as possible in every way you can think of, you're doing the job well. Just try to come up with multiple solutions to the same problem, then decide which one is the best solution for that specific situation. That will help keep the thermometer low and keep you thinking creatively, which is pretty much the definition of a win-win situation.