Logic gate

From Valve Developer Community
Revision as of 17:03, 27 September 2010 by Thelonesoldier (talk | contribs) (cleanup tags. this article is a disaster)
Jump to navigation Jump to search
Broom icon.png
This article or section needs to be cleaned up to conform to a higher standard of quality.
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.
Broom icon.png
This article or section should be converted to third person to conform to wiki standards.

In your level, you can make two buttons that open a door when both buttons are pressed. Simple. If you want to open a door when the button is not pressed, you can do that too. Now, if you want to open a door only if two defined buttons are pressed and one button is left unpressed, and when that button is pressed the door won't open, it's a bit more complicated. However, using Logic Portals Items and Logic Gates, you can do it.

Logic Portals Items like the superbutton, the double-doors and the switch for example were redesigned to work using a system of logic gates. The following tutorial won't explain how to create one but how to use it with an explanation of the logic behind it. It offers a powerful system to make puzzle levels.

The cube dispenser is an exception. Its main difference against the classic cube dispensers is that it can deliver multiple cubes with a fixed number of cubes in each level.

Basic usage

The superbutton and the button are input devices for the player. When you make them work, it outputs a boolean value: one or zero. It means true or false. This state is stored in an entity named logic_branch.

The double doors is an output device for the player. Giving a true input opens them, false closes them. An entity named logic_branch_listener listens to a logic_branch containing a boolean value. When the boolean value changes, the state is read once again and processed.

Logic Gates

Quick logic_branch_listener explanation

The logic_branch_listener has how it works in the name. It listens to one or more logic_branches' states and triggers it's outputs when and only when the state of a logic_branch is modified. So if a logic_branch gets a SetValue and the value being set is the same as the value it already has, it will NOT trigger it. This is useful for Valve's purposes, but is NOT the way a logic gate is meant to work.

To make a gate work, the only thing you have to do is to link the logic_branch_listener to one or more logic_branches coming from a Logic Portals Item, or to the end of another Logic Gate Output Branch.

The AND Gate

The AND gate listens to a list of multiple output logic_branches and outputs a TRUE value when all the branches the entity listens to have a TRUE state.

So in the logic_branch entity, we need to set it to work when all is TRUE.

AND Gate (multi-input)
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnAllFalse branch_Z_N SetValue 0 0.00 No
Io11.png OnAllTrue branch_Z_N SetValue 1 0.00 No
Io11.png OnMixed branch_Z_N SetValue 0 0.00 No

The OR Gate

The OR gate works whenever one or several logic_branches the entity listens to have a TRUE state.

So in the logic_branch entity, we need to set it to work when the input have mixed values of TRUE and FALSE, or when all are TRUE.

OR Gate (multi-input)
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnAllFalse branch_Z_N SetValue 0 0.00 No
Io11.png OnAllTrue branch_Z_N SetValue 1 0.00 No
Io11.png OnMixed branch_Z_N SetValue 1 0.00 No

The NOT Gate

The NOT gate outputs the contrary of the single branch it listens to. So when the output branch is TRUE, it outputs FALSE and when the branch is FALSE, it outputs TRUE.

NOT Gate (single-input)
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnAllFalse branch_Z_N SetValue 1 0.00 No
Io11.png OnAllTrue branch_Z_N SetValue 0 0.00 No


The NAND Gate

The NAND gate listens to a list of multiple output logic_branches and outputs a TRUE value when not all the branches the entity listens to have a TRUE state. It is essentially a NOT AND gate.

So in the logic_branch entity, we need to set it to work when the input have mixed values of TRUE and FALSE, or when all are FALSE.

NAND Gate (multi-input)
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnAllFalse branch_Z_N SetValue 1 0.00 No
Io11.png OnAllTrue branch_Z_N SetValue 0 0.00 No
Io11.png OnMixed branch_Z_N SetValue 1 0.00 No

The NOR Gate

The NOR gate listens to a list of multiple output logic_branches and outputs a TRUE value when neither of the branches the entity listens to have a TRUE state. Again, it is essentially a NOT OR gate.

So in the logic_branch entity, we need to set it to work when all are FALSE.

NOR Gate (multi-input)
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnAllFalse branch_Z_N SetValue 1 0.00 No
Io11.png OnAllTrue branch_Z_N SetValue 0 0.00 No
Io11.png OnMixed branch_Z_N SetValue 0 0.00 No

The XOR Gate

The XOR gate listens to a fixed number of two branches and outputs only when one, or the other is TRUE, not both.

So in the logic_branch entity, we need to set it to work when the input have mixed values of TRUE and FALSE.

XOR Gate (two-input)
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnAllFalse branch_Z_N SetValue 0 0.00 No
Io11.png OnAllTrue branch_Z_N SetValue 0 0.00 No
Io11.png OnMixed branch_Z_N SetValue 1 0.00 No

The XNOR Gate

The XNOR gate listens to a fixed number of two branches and outputs only when both have the same state, either TRUE or FALSE, but not mixed.

So in the logic_branch entity, we need to set it to work when all are TRUE, or when all are FALSE.

XNOR Gate (two-input)
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnAllFalse branch_Z_N SetValue 1 0.00 No
Io11.png OnAllTrue branch_Z_N SetValue 1 0.00 No
Io11.png OnMixed branch_Z_N SetValue 0 0.00 No

Logic Items

Logic Portals Superbutton

The Logic Portals Superbutton is quite simple to understand. Two things can push the button: the player and a cube. Let's split those two things into two trigger volumes: One tiny cylinder that filters boxes like it does in regular superbuttons, and a box that only the player can trigger. Each trigger changes the state of two separate branches. We link each of these branches to a branch_listener which is an OR gate, and outputs this state into the output branch.

LPI Superbutton.png

Logic Portals Multi-cube Dispenser

LPI CubeDispenser.png

See also

External links