This guide will accompany my latest video tutorial on sequential switches. The topic is somewhat complex, so I wanted to provide supplemental material in text form.
Sequential switches allow you to create an "and gate" (one which requires multiple conditions to be met before performing an action) where the required conditions must be completed in a specified order.
This scripting will be best used in puzzles where a player can be required to complete multiple challenges in a specific order. Mini games and even linear progressive infection maps could make use of this as well. I would recommend placing the items which provide feedback on players' progress through the sequence (the cones, in this case) above the door they are trying to open rather than above the switches themselves. Of course, opening a door does not need to be the end goal. Any action can be attached to the activation of the seventh power channel which is the result of completing the sequence.
For this setup, I have used three ordered switches. The scripting can be extended to include additional switches, but the amount of scripts required to do so will grow exponentially with each additional switch. For a series of three, approximately 35 scripts are required.
I've laid out all of the logic at work here below. You can see the exact scripts this has translated into in the next section, but this should provide a clearer picture of exactly how this works using simple if, then statements. First thing's first, we need to set each of our first three power channels off. Channels begin in a null state, but logic further down the chain will require them to start in the off state. From here, interacting with each switch should turn its respective channel on.
If: match start, then: alpha offNext, we need to walk through the sequence and determine what should happen when each switch is turned on at the correct time. We'll step through it in order and this will affect our secondary group of power channels. Once these channels are all on, meaning the sequence is complete, we'll turn on our last power channel which will activate the outcome of the whole sequence (opening the door, in this case).
If: match start, then: bravo off
If: match start, then: charlie off
If: interact with switch 1, then: alpha on
If: interact with switch 2, then: bravo on
If: interact with switch 3, then: charlie on
If: alpha on, and: bravo off, and: charlie off, then: delta onNow we've got the outcome for the sequence being completed properly down. We need to reset everything if any switch is flipped out of order. We need to account for every possible way the switches could be flipped in the wrong order.
If: alpha on, and: bravo on, and: charlie off, then: echo on
If: alpha on, and: bravo on, and: charlie on, then: foxtrot on
If: delta on, and: echo on, and: foxtrot on, then: golf on
If: alpha off, and: bravo on, then: delta off
If: alpha off, and: charlie on, then: echo off
If: bravo off, and: charlie on, then: foxtrot off
If: delta off, and: echo on, then: echo off
If: echo off, and: foxtrot on, then: foxtrot off
If: delta off, then alpha off, and: bravo off, and: charlie off
If: echo off, then alpha off, and: bravo off, and: charlie off
If: foxtrot off, then alpha off, and: bravo off, and: charlie off
The last thing we need is feedback for the player. In this case, we're associating a cone with each switch and changing its color upon activation. If these three objects are physically placed in the right order, they can guide players through the sequence and show their progress.
If: alpha on, then: color change green on object 1Scripts:
If: alpha off, then: color change orange on object 1
If: bravo on, then: color change green on object 2
If: bravo off, then: color change orange on object 2
If: charlie on, then: color change green on object 3
If: charlie off, then: color change orange on object 3
You can see all the scripts this logic translates into below. With the exceptions of the interaction with the switches and the color changing on the cones, everything is crammed into three script brains. It's a bit jumbled and harder to follow here which is why I laid everything out above.
Switches:And there you have it! Feel free to download Sequential Switches from my files to take a look in forge if that helps you. I hope some of you find this useful or at least interesting, and I look forward to seeing what you come up with!