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

Each module has a Statemachine, which contain 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.

EXAMPLES

In 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)
Here 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