Skip to content
oleegholm edited this page Jan 18, 2012 · 17 revisions

Each module has a Statemachine with several states. Any user interaction is detected by and processed within the Statemachine. Inputs can come from either from KEYS or MOUSE, and are fetched using Case Matches. When an event corresponds to the Case Match in the active State in the Statemachine, the code block within the given state is executed.

Conceptually, the hierarchy is as follows:

  • Statemachine
    • States ('Start, 'End, 'Point, etc.)
      • Case matches (Case MouseDown(), Case _, Case KeyDown etc.)
A statemachine includes a minimum of two states: 'Start and 'End, but more can be added.

STATES

The states in a module defines the progress of the module, based on user input. When the module starts, exits, draw, forwards to another module. Here are two examples of how a state might work.

EXAMPLES

In this first case the module needs to react to a mouse click and store the coordinate point in a value:

Case MouseDown(p, MouseButtonLeft, _) :: tail => {point = p}.


In //Case MouseDown// a mouse click is registered, and the coordinate is given to the variable //p//. Inside the code block p is passed on to a variable //Point//, which can be accessed from anywhere within the module.

Case matches can be used to do many different things. This case is a part of the Rectangle module, in which a MouseUp triggers this code:

case MouseUp(point, _, _):: tail => {
points = points :+ point
if(points.length == 1) {
Goto('SecondPoint)


In this example a point is added to a list of points. If there is already a points in the list, it means that the first corner of the rectangle has already been defined. In this case //Goto('SecondPoint) proceeds to execute the State SecondPoint, in which the rectangle is finalized.
Clone this wiki locally