How to buffer events (and use it with a counter)
http://i.imgur.com/PeQLy.jpg
Hi there again! Remember that previous tutorial, How to make a simple counter? Today we are turning that into a reliable dead body counter.
N.B.: this tutorial covers the logic that I am using for my new level's custom score counter, but I think a death counter is a much less abstract example. For reader's convenience.
http://i.imgur.com/Si1Ux.jpg
Here we have a dirty commie sackbot. The pests come in droves and it is best to heat up the cold war a bit and turn them into dust! As you can see, we are using a simple bullet hit detection that triggers a 0.1s timer which in turn kills the bot through a destroyer. Nothing fancy. At the same time it gets hit, it triggers a 1-shot counter connected to a tag. The counter is to make sure that the signal we are creating by activating the tag lasts as short as possible.
http://i.imgur.com/pn8Iq.jpg
DIE COMMIES!!!
http://i.imgur.com/FeZwT.jpg
Here we have our counter logic again and this time not a button but a tag sensor - registering the death of a dirty commie sackbot - triggers the counting mechanism to add up. (N.B.: in the screenie, the sensor is supposed to go into the positive input of the signal combiner, not the negative)
But these commies won't stop coming and we might just shoot two at once occasionally... Now our tag sensor will fail, because it does not distinguish between one tag active and multiple tags active. What we need to do, is pick up such an exceptional event and fire off multiple pulses into our counter caused by this event.
http://i.imgur.com/jyEY2.jpg
Here we are setting up one way to do it. Replace the tag sensor by a new microchip and put two tag sensors on it; one registering (at least) ONE sackbot death tag and one registering (at least) TWO sackbot death tags. In case two die, the first sensor is also triggered and we want to make sure it is either the one or the other. You see that setup demonstrated above.
http://i.imgur.com/iWnKP.jpg
Here we've added some more logic. When only one red dog dies, that signal goes out the other side of the chip as one pulse into the counting system. When two traitors of freedom die simultaneously, it triggers the reset of an inverted 2-shot counter. When this counter is reset it activates a small microchip that contains a pulser (a NOT gate feeding itself, creating a very rapid pulse). During a brief moment this pulser increases the counter with two pulses until it is full again and shuts the pulser down. During that time the pulser will have given off two quick pulses into the counting mechanism.
So, when two stinking commies die simultaneously, it creates two rapid pulses inside the system.
Perfect, right? NJET!!
I used to think this would work, but it is an unreliable setup; when after a simultaneous death, during the short moment that the system is giving off two pulses, if another bot dies, this pulse will coincide with the double-pulse going in at the same moment, causing one to get lost.
Awful commies! Freedom must prevail!!
http://i.imgur.com/EAcDs.jpg
Yikes!! What's this thing? It's freedom, baby.
Again, this is a bit complex, but stay with me, okay? This is multi-channel buffer that stores a single and double death event separately and unloads these events into the counting system whenever there is something to unload; on its own pace, even moments after the dirty commie rightly so bit the dust.
Two tag sensors, one for one, one for two death tags. They each up a counter of their own through a signal combiner. The counter goes into a positional sequencer that has a battery across its entire canvas. When the counter is empty, the cursor on the sequencer will be on the 0 position and the battery will not give off a signal; however, when the counter is of value 1 or higher, the battery gets activated. Thus the sequencer detects whether a counter's value is not 0. These batteries lead to a 3-gate AND gate.
On the other side of the chip we have a pulser (the purple NOT gate), leading into each AND gate. This pulser also passes through a red AND gate into the cycle input of a 2-gate selector. Each output of the selector goes to another AND gate. What will happen now is that the pulser causes the selector to rapidly switch between buffer channels; if a channel has a counter set to 1 or greater, it will activate the channel's AND gate.
An active AND gate goes to the negative input of the signal combiner, causing to count down the channel's counter. When the counter reaches 0 again, the channel stops passing on pulses. But as long as the AND gate is active, pulses will go to an OR gate where all channels send their pulses to; the output of that OR gate goes into the counting system. Also, separated by another OR gate and a NOT gate, these pulses go into the red AND gate, causing the cycling between channels to halt and unload that channels counter. When unloaded, the cycling continues until another filled channel is detected.
Freedom prevails!!
http://i.imgur.com/M1BYZ.jpg
Oh no!! Invasion!! Blow up the truck.
In this last example we'll be blowing up a truck and kill ten commies at once. Our system cannot really deal with ten simultaneous death events. We can extend the buffer logic to include ten channels, but there is another way. We know that a truck carries 10 kremlin dwellers and they will all die at once. So, why not increase our counting system with 10 instantly?
http://i.imgur.com/bZzdj.jpg
Here we have such a setup. A dedicated tag sensor registers the destruction of a truck (same logic as with a bot), goes to an OR gate and into the signal combiner that goes into the second selector on our counting logic, upping the count with 10 instantly.
But what if a truck dies at the same moment that a single bot dies who is causing the count to go up from 9 to 10? Then the truck event and the pulse from the red chip arrive at the OR gate at the same time and one of them is lost.
http://i.imgur.com/XRTzM.jpg
Same buffer, but instead of two tag sensors, the two pulses go into their own channel. Enjoy your rock-solid commie corpse counter!
http://i.imgur.com/Z646j.jpg