Multiple Choice
By Richard Clark

There are times when the level designer will need to evaluate a range of conditions. For example, there may be several activation lines on a level. Each line activates a different sequence of events. To easily handle such a situation, ACS has the Switch statement.

    Script 1 (int lineid)
    {

        switch (lineid)
          {
           case 1:
             ...commands..
             break;
           case 2:
             ...commands..
             break;
           default:
             ...commands..
          }
    }

Script 1 takes an integer is a line id. When the script is called, the switch statement evaluates the contents of lineid. If lineid = 1, the commands following case 1 will be executed. If the lineid = 2, the commands following case 2 will be executed. Notice you don't need { } to enclose the statement after the case.

The keyword break means to "break out" or exit the switch. If break is not used then processing proceeds to the next line in the script. Normally, when a case has been handled, then the switch should be exited.

The last item in the list, default, will execute if none of the other cases match the passed variable. For example, if lineid = 0, then the commands following default would be executed. Default is optional and does not have to be present.

The utility of this construct becomes apparent at once. Instead of creating a script for each line id, simply create one script with the switch statement and execute any necessary commands within a single script call. If any of the conditions change, the change to the script is localized in one script call.