New logic gates part two

So in the last post we had a map hack set-up to create a “gate”, which can be set to open or closed, so that it behaves like a trigger_relay only when open. This is helpful in itself, but we can do more by combining two or more gates. Today we’ll create AND, OR and IF-ELSE logic gates, and don’t forget to stick around to the end where I post an example .map file with prefabs for all the gates.

The first construction we will create is an AND gate. This acts like a trigger_relay when both gates are open. The simplest way to make this is just two gates connected in series. By this I mean that the input triggers a query of the first gate. If that gate is open, it triggers a query on the second gate. If that gate is open, fire the output. This pattern obviously generalises to 3 or more tests very simply.

The OR gate acts like a trigger_relay if either of two gates are open, and it’s actually a bit more complicated to build. The trick is to physically overlap a pair of triggers, and aim a single “axe” attack at the overlap of the two. The difficulty comes from the “lightning” info_notnull. To allow the gate triggers to be toggled individually, we must ensure each lightning entity can only strike its own gate. The first step is to make sure the gate triggers only partially overlap, and place the lightning entity in the non-overlapping sections of each gate.

This is not enough though! Remember from last time that the lightning fires in an indeterminate direction. This means there is a risk that if one gate is already switched off, triggering its off switch again will send the spark shooting into the other gate, incorrectly turning that off. So once we have placed the lightning entities in separate quarters, we need to wall them off from the other gate with solid brushes. The following diagram shows the recommended set-up:


The blue and red intersecting rectangles are the pair of gates. The orange brushes are solid walls. The upper purple squares are the info_notnulls which fire lightning to toggle each gate closed. The central purple square is where the pair of axe info_notnull entities sit to query if either gate is open. Don’t forget that it takes a pair of entities to generate a single axe attack, the gates do not have individual axe attacks, they share one attack caused by two entities. I have no doubt this is the hardest part of the article, it may help to grab the example map from below and take a look at a completed example.

An alternative approach to creating an OR gate might be to copy the example of the AND gate, but in parallel rather than series – have two separate gates and an axe for each one, so the same targetname fires each of the axe info_notnull pairs. An issue with this approach is that if both gates are open, the intended event gets fired twice, rather than once. If you’re trying to toggle a door with your output, the second trigger will cancel out the first! The recommended set-up from earlier avoids this, because an axe attack can only ever strike one target – if both gates are solid the engine chooses one to hit arbitrarily.

With a little rewiring the OR gate above can be converted into an IF-ELSE set-up. The trick is to make the targetname which opens the left gate the same as the name to close the right gate, and vice-versa. Then modify the left and right gates to target different event names. Exactly one of the gates will be solid at a time, and that gate will be struck by the axe on a query. Don’t forget to initialise the gate at the start of the map, as it will spawn in an indeterminate state – but at the same time make sure to wait until after the 2nd frame, so that all the set-up functions have completed.

All that remains is to offer you the prefabs. Click here to download some templates of the maps hacks from these two posts


One thought on “New logic gates part two

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.