0 votes
by (110 points)
In the building the player is infiltrating, the lift (elevator) is deactivated and all the stairwells are being patrolled by armed guards who have orders to arrest (or shoot) any unauthorized persons the catch trying to take the stairs. The puzzle for the player would consist of trying to reactivate the lift by reconnecting three wires in the correct sequence. If they get the sequence right, the lift becomes functional and allows them to bypass the guards in the stairwells. If they get the sequence wrong it either won't work or, in the worst case scenario, will trigger the alarm system. Any suggestions on coding the puzzle?

1 Answer

+1 vote
by (159k points)

Please use the Question Tags to state the name and full version number of the Story Format you are using, as answers can vary based on that information. I will assume you are using SugarCube v2.21.0 or later.

I suggest use an Array and store the name of each wire in it as it is connected, this will allow you to check the order of those names.

The following rough prototype includes links for connecting each of three coloured wires, for testing if all three have been connected and that they were connected in the correct order. It also has a link for resetting / un-connecting all the wires.

<<set $connected to []>>\
Message: @@#message;No wires are connected.@@

<<link "Connect Red Wire">>
	<<run $connected.pushUnique("Red")>>
<</link>>

<<link "Connect Green Wire">>
	<<run $connected.pushUnique("Green")>>
<</link>>

<<link "Connect Blue Wire">>
	<<run $connected.pushUnique("Blue")>>
<</link>>

Determine if all three wires have need connected and that they were connects in the order of Red, Green, Blue.\

<<link "Test Connections">>
	<<if $connected.length lt 3>>
		<<replace "#message">>You need to connect all three wires.<</replace>>

	<<elseif $connected[0] is "Red"
				and $connected[1] is "Green"
				and $connected[2] is "Blue">>
		<<replace "#message">>The wires are connect correctly.<</replace>>

	<<else>>
		<<replace "#message">>The wires were not connected in the right order.<</replace>>
	<</if>>
<</link>>

<<link "Reset all connections">>
	<<set $connected to []>>
	<<replace "#message">>No wires are connected.<</replace>>
<</link>>

I suggest you read the relevant SugarCube 2.x documentation for any of the above macros or functions you're not familiar with.

...