Logic Gadgets: Exclusive Gate

 

Icon
Name of gadget Exclusive Gate
Section Logic & Processing
Number of Tweak pages 1
Author LadylexUK, QuietlyWrong
Last updated 02 Sep 2019 [v1.08]

Description

An Exclusive Gate is like a switch: it can be open or closed, letting a signal pass through it or stopping it and sending a signal of 0 (off) instead. What makes it special is that it co-ordinates itself with all other Exclusive Gates of the same name in your scene, such that no more than one is ever open at a time. It is therefore an unusual gadget in that it’s highly unlikely to be used on its own, only in combination with other exclusive gates.

Any input signal above zero is considered to be a “request” for the gate to open (or, if already open, remain open). How Dreams decides which of two or more simultaneous requests it will accept – is dependent on all of the gates’ various tweaks and inputs.

All exclusive gates with the same name work together, with no wires needed to connect them. You can prioritise gate opening in more than one way, and can interrupt, pause or queue gates no matter how many are currently in the scene, making them very versatile.

The sheer variety of ways that a group of gates can interact with each other makes them one of the most intimidating gadgets, so it is worth knowing exactly how Dreams chooses to close one gate and open another. To that end, a full breakdown (“Which Gate Wins?”) is provided towards the end of this article! It’s well worth a look if you want to get the most out of these gadgets.

They are useful, for example, for stopping two incompatible actions from happening at the same time (such as jumping and sitting). They can also be used to give one object priority over any number of others, for example to trigger only one wedding guest NPC at a time to try to address the player’s bride character.

A nice side-effect of the gates’ queueing system means they can be used to cycle repeatedly over a group of objects, one at a time, for example in a targeting system or an inventory, and it’s not necessary to know in advance how many objects are in the cycle. An example of how to do this is given at the end of this article.

Note that although you can never have more than one gate open at a time, it is still possible to have none open if there are no active requests. Also, because Dreams has to check every gate against every other, there is a very short delay (one frame) between the signal that enters the gate’s input and the one from the output.

 

Example Tutorial (adapted from Media Molecule)

  1. Place a microchip and open it up. This is where we will put all our gadgets.
  2. Place an exclusive gate on the chip and give it a unique name, such as ‘Lights controller’.
  3. Tweak the exclusive gate so reset mode is manual.
  4. Clone the exclusive gate and stamp the copy on the chip, guaranteed to be identical to the first (in both name and reset mode).
  5. Stamp two timers, two lights and a controller sensor on to the chip.
  6. Tweak the controller sensor to be remote controllable.
  7. Connect the square output on the controller sensor to exclusive gate 1’s gate input and the X output to the gate input of exclusive gate 2.
  8. On each timer, connect timer finished (pulse) to reset timer to make a loop.
  9. Connect each timer output to the power node of a different light.
  10. Connect each exclusive gate output to one of the timers.
  11. Connect each timer finished pulse output to the close gate inputs on gate 1 and gate 2 (both).
  12. Go to play mode.
  13. Press X to turn one light on and immediately press square to turn the other light on.
  14. You will find you cannot until the timer runs out because while one gate is open the other is closed, blocking the signal to turn on the light.

See the end of this article for another example, using exclusive gates to cycle between objects.

 

Tweak Menus

  1. Gate Input
    1a. Input
  2. Gate Output
    2b. Output
  3. Gate Sync
    3a. Input
  4. Close Gate
    4. Input
  5. Active
    5b. Output
  6. Priority
    6a. Input
    7a. Ouput
  7. Interrupt On/Off
    7a. Input
    7b. Output
  8. Reset Mode
  9. Gate Colour
    9a. Input
    9b. Output
  10. Power
  1. Gate Input
    This is where you connect the signal that you want to pass through the gate. A new signal will be treated as a request to open the gate but only if its value is above zero. The value of the signal may also be used to give precedence to this gate over others (see Which Gate Wins?, below).
  2. Gate Output
    If the gate is open, this is where the input signal will be output from. Note that (for technical reasons) there is a one frame delay between the input and output, unlike most other wired gadgets. When the gate is closed, no output is provided here.
  3. Gate Sync
    By default, this is on, meaning the gate behaves as normal. With Gate Sync off, the gate holds on to any request to open, meaning a closed gate with Gate Sync off will remain closed no matter what, until Gate Sync is activated. In queue mode, an existing request can be paused by turning gate sync off and then on again later.
  4. Close Gate
    As a general rule, once a gate is open, it stays open until it is “interrupted” by another gate or it is closed. A new signal to the Close Gate tweak will force the gate to close. The Close Gate input will also revoke any outstanding requests that have yet to be fulfilled (queue mode).
    Note that holding this input on will not close the gate again if it re-opens – it is necessary to send a separate “close” input each time.
    If a gate is still issuing a request to open (i.e. it has an input), it may yet “beat” all the other gates and immediately re-open.
  5. Active
    This produces a continuous “on” signal while the gate is open, regardless of the current Gate Output value (which might be zero, for example).
  6. Priority
    A gate with higher priority (higher numerical value) will always open in place of a gate with lower priority when it makes a request (receives an input). This is fundamental, overriding all other considerations. If the open gate in a scene has the highest priority value, it will remain open, even with no input signal. Only if two or more gates share the highest priority in a scene will any other considerations determine the currently open one.
    In practice, this means that changing the priority value of a gate (with a positive Gate Input) so that it exceeds that of all others will always cause it to open (as long as its Gate Sync setting is on), which can be useful.
  7. Interrupt On/Off
    Any gate that has this tweak turned on will be able to close any other gate (of the same priority) if it has a higher (positive) Gate Input value. For example if you want the gate furthest from the ground to open, enable this tweak for all such gates and feed a measurement of each gate’s height into its Gate Input (well, the height of whatever it is associated with). As gates move up and down, the highest will always “interrupt” the others. Only the Priority setting can take precedence over an Interrupt.
    If multiple gates have Interrupt On persistently active and all have the same Gate Input value, Dreams holds one gate open but monitors the Interrupt On/Off settings. If one of these gate’s Interrupt setting switches to Off and then back to On, it will take precedence and open.
  8. Reset Mode
    Behaviour of Exclusive Gates is partly determined by the Reset Mode, which determines the methods for closing gates and for determining the order in which requests to open will be fulfilled.

    • Automatic
      In this mode, an open gate will close itself automatically if its Gate Input value falls to zero (or less). When it closes, the next gate to open is determined by current Gate Input values.
    • Manual
      In this mode, once a gate is opened, it remains open even when its Gate Input signal falls to zero (or less). When it does close, the next gate to open is determined by current Gate Input values (highest first).
    • Queue
      In this mode, requests are added to a queue and fulfilled in turn, even if the actual Gate Input falls to zero (or less) in the interim.
      Once a gate is opened, it remains open even when its Gate Input signal falls to zero (or less). When it does close, the next gate to open is still determined by current Gate Input values, but if the highest of these is shared between several gates, the historic Gate Input values are used. The gate which has the highest historic value while on the queue is open; if values are equal, the oldest request comes first. Gates can only place one request on the queue at a time.
  9. Gate Colour
    Here you can choose a colour for the gate’s gadget appearance – this is simply to make it easy for you to distinguish different gates when you need to do so.
  10. Power
    This is where you turn the gadget on/off. When off, all outputs are off. However, it is noteworthy that if a gate in queue mode adds a request to open before it is prematurely powered off, this information is retained so that the gate resumes its place in the queue when powered back on again.

Which Gate Wins?

Any time an Exclusive Gate receives a signal to its Gate Input that has a value above zero, it sends a “request” to open (if it doesn’t already have an outstanding request in queue mode). Every frame (1/30th second, in game), all gates with requests are compared.

In manual and automatic Reset Modes, only current requests are meaningful whereas in queue mode, historic requests remain relevant until they are closed.

Here is the sequence of rules by which Dreams determines which request takes precedence:

The highest-precedence scenarios will open a new gate even if that means having to close another gate. Even a gate with Gate Sync off will be closed.

  • If any gate has highest priority, it is opened.
  • If several have the same highest priority, look at those with Interrupt On/Off active
    • Of these, whichever has highest Gate Input value is opened.
    • If several have the same Gate Input value, precedence is given to a gate that has only just (this frame) had the Interrupt On/Off setting activated and that gate is opened.
    • If several matching closed gates all have only just had Interrupt On/Off activated, the (arbitrary) sequence number is used to open one gate (see below for more about this).
    • If there are several matching, highest input value gates with Interrupt On/Off active, but none has changed in the last frame, the currently open gate will remain open.
  • If there are no gates with Interrupt On/Off active any currently open gate will remain open.

The following scenarios cannot override an already-open gate, only taking place when all gates are closed:

  • If no gate is open, the gate with the current highest Gate Input value is opened.
  • If gates are still tied, the Reset Mode is checked; queue mode is opened in precedence over manual mode, which is in turn opened in precedence over automatic mode.
  • If several gates in queued mode are tied, the highest historic input value (highest Gate Input value since the request was created) is used to determine the gate to be opened.
  • If several queued gates are tied for historic value, the gate with the oldest request is opened.
  • Finally, the (arbitrary) sequence number is used to open one gate.

In most cases, the input signals and gate settings can be used to determine the open gate but when all else is equal, Dreams falls back on a hidden “sequence number” (as referenced above) to discriminate between them. This is a unique identifier number, relatively arbitrarily assigned. As a rule, gates stamped into the scene more recently have higher sequence numbers and therefore a newer gate will tend to take precedence over an older one. With no control over of this identifier, you can’t assume it will behave consistently as changes are made to your level or updates are made to Dreams, so don’t make intentional use of it.

Example Tutorial for Looping Behaviour

The exclusive gate is ideal for looping over a group of objects, one at a time, because it works dynamically – it adapts to any number of like objects that are in its scope with some pretty simple logic. The player might want to cycle through an inventory, or enemy targets, and – as long as you’re happy to go just one way through the list – it could hardly be easier to implement. Here’s a very basic example.

  1. Go into Sculpt Mode and stamp down a cube.
  2. Tweak the cube so it is grabbable.
  3. Tweak the cube’s Glow setting to about 40% brightness.
  4. Grab a microchip from the gadgets menu and snap it on to the cube.
  5. On to the microchip, stamp a NOT gate, a grab sensor and an exclusive gate.
  6. Open the exclusive gate’s tweak menu and give the gate a unique name, like “Cube cycle”.
  7. Tweak the gate’s Reset Mode to its “Queue” setting.
  8. Connect the NOT gate’s output to the gate’s Gate Input port (a NOT gate with no input is a very cheap way of generating a constant signal).
  9. Connect the grab sensor’s Grabbed output to the gate’s Close Gate input port.
  10. Connect the gate’s Gate Output port to the cube’s Glow tweak.Exclusive Gate looping example
  11. Now make a few clones of the original cube.
  12. Go into test mode and grab the currently-lit cube to close its gate. Repeat and see how you can loop through all cubes before starting again!
    Dreams Exclusive Gate loop example

So why does this work? The key here is that the gates are just about identical, so the queue itself is the most important factor in determining the order of precedence.

All of the gates are constantly requesting that they be opened, thanks to the constant ON input. So Dreams opens one of them and the rest have to wait. When the open gate gets closed, it immediately puts a request back on to the queue but this is a newer request than the others so it has lowest priority. Everything else being equal, all the others will open before it gets its next chance.

And so on with the next gate, exactly the same happens, until all have had a turn and the first one re-opens. It doesn’t matter whether there are 2 or 200 cubes, or if they get deleted or created mid-test, it keeps on cycling.

 

Lex Tips

QW Tips

If you fail to name your gate, it will have the default (“Exclusive Gate”) and will work with any other unnamed gates; this is almost always A Bad Idea because if you have more than one group of named exclusive gates in your scene, it makes it much easier for a gate to end up in the wrong category and your logic harder to debug.

You should give gates a meaningful name that tells you what logic they are controlling. Best practice is to stamp one gate, name it, and then make clones of it for any other gates in the same group. That way, there’s no danger of mistyping the name.

 

Useful Tutorials

Comments and Feedback

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

WordPress.com Logo

You are commenting using your WordPress.com 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.

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: