Skip to content
oleegholm edited this page Jan 18, 2012 · 1 revision

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