Switch

The Switch accessor (class ) implements a switch statement.

Parameters

  • Switch: An expression that should return an integer. Depending on its result, the attribute 0...N will be assigned the value of the parameter.

  • case 0: Must be an attribute of the prototype or the value "". If Switch evaluates to 0, the behaviors of the attribute named in this parameter will be executed.

  • case 1: If Switch evaluates to 1, the behaviors of the attribute named in this parameter will be executed.

  • ...

  • case N: If Switch evaluates to a value equal to or greater than N, the behaviors of the attribute named in this parameter will be executed.

Example

A traffic light with varying settings can be implemented like this:

Value Integer

do

Switch Value

case 0 doRed

case 1 doOrange

case 2 doGreen

case 3 Anomaly

 

doRed

do

greenEllipse.visible=False

orangeellipse.visible=False

redEllipse.visible=True

doBlink=False

 

doOrange

do

greenEllipse.visible=False

orangeellipse.visible=True

redEllipse.visible=False

doBlink=False

 

doGreen

do

greenEllipse.visible=True

orangeellipse.visible=False

redEllipse.visible=False

doBlink=False

 

Anomaly

do

greenEllipse.visible=False

orangeellipse.visible=True

redEllipse.visible=False

doBlink=true

 

doBlink Boolean

do

blink orangeEllipse.visible 150