Using switches and buttons

This tutorial explains how to create basic buttons, switches, and levers.
It assumes that you already have a fully working mission, with the scripts Convict and Gen loaded, a linked starting point, a room-brushed area to build in, etc.

First of all, you need to create a button: open the Object Hierarchy, navigate to Button (-448), hit Create, and place a button in the world.

There are a lot of different things that a button can affect, from physical things such as doors and lights to more complicated behind-the-scenes 'traps' for modifying quest variables and teleporting objects.

A perfect example of something that can be activated via buttons and switches is an alarm, so create a MechRedAlarm (-1900) and memorise its object number.
Make sure that the MechRedAlarm is inside a roombrushed area, or you will not be able to hear it when it sounds.

Now, select the button, and hit the 'Links' button at the bottom-centre of the DromEd window.
The Links window should appear. Hit the Add button and select ControlDevice from the Flavour pull-down menu.

Enter the object number of the button (displayed in the title bar of the Links window) into the From field, and the object number of the MechRedAlarm into the To field.

Now go into Game Mode and frob the button.
If everything went according to plan, the MechRedAlarm should start ringing loudly.

Note that no matter how many times you press the button, it only ever turns the alarm on, never off.
This is because buttons use the StdButton script, which only sends an 'On' message down its ControlDevice links when frobbed. (Although this can be changed by using Invert in the Script->Trap Control Flags property so that the button only sends 'Off' messages.)

Levers, on the other hand, use the StdLever script, which sends both 'On' and 'Off' signals; the former when the moving part of the lever (called the joint) reaches the end of its motion, and the latter when the joint returns to its starting position. That is to say, an 'On' signal is never sent if the lever does not reach the end of its motion; for example, if the player frobs it again before it has reached the 'on' position.

(You can create your own buttons by giving an object the StdButton script and the Engine Features->FrobInfo property, which must have its World Action set to Script. Creating custom levers is a fair bit harder, as it requires to the use of the Tweq->Joints property, the usage of which is far outside the scope of this tutorial.)

The procedure for creating a lever is practically the same as that of creating a button.
Simply find the appropriate type of lever in the object hierarchy (look under Levers (-442)), place it in the world, and create a ControlDevice link from the lever to whatever you want it to activate.
Try creating a BigFloorLever (-446) and linking it to your MechRedAlarm.
You should now be able to turn the alarm on and off by use of the lever.

Button and levers are not the only things that can send ControlDevice signals.
There are also many traps and triggers that can be used, such as the TrigFlicker, TrigDoorOpen, TrigRoomPlayer, and TrigWorldFocus scripts, to name a few.