10 – Finite-State Machines (Advanced)

10 – Finite-State Machines (Advanced)

Overview

Assignment of Pages to States

Timed Events

  • Definition
  • Repeated Timed Events

Timer Component

Task Initialization

Regions

  • Multiple Nested Finite-State Machines

Assignment of Pages to States

Contrast

Links:

Components support Link Page that can be used to define Regular Links and Conditional Links.

Events:

Components support Link ... Event that can be used to trigger FSM Events.

Another Approach to Change Pages:

  • Pages can also be linked to States:

  • State-change triggers page change.

Timed Events

The CBA ItemBuilder supports Timed Event that trigger automatically after a given amount of seconds.

Definition:

Events: EV_Example 3.5;               // 3.5 = Three and a half second.
Rules: ST_Start -> ST_Running {true}

Application

  • Timed Events are very powerful (e.g., to change the item automatically).
  • Examples

    • Restrict the available time on one particular page or in a section and automatically navigate to a next page.
    • Trigger a dialog or timeout page that navigates to the next page.
    • Show a notification or warning, at a certain point in time.

Repeated Timed Events

By default, timed events fire only once:

  • Each Timed Event is started on State-entry and fires at maximum once.

However, remember Self-Transition (StateA => StateA {Event}) versus Internal Transitions (StateA internal {Event}):

  • Hence, if a repeated Timed Event is needed, restarting the Timed Event with an Self-Transition StateA => StateA {Event} is necessary.

Illustration for => vs. internal:

  • If the state changes before time is elapsed, the Timed Event is not triggered.

Timer-Component

The CBA ItemBuilder provides a simple Timer component that can be used to visualize time on pages.

Two modes:

  • Stopwatch
  • Linked to a Timed Event

  • Link Timed Event

  • Configuration

    • Orientation
    • Run Forward
    • Show Remaining Seconds

Count Time with Variables

Repeated Timer (Self-Transition)

The CBA ItemBuilders Timer component has a limited set of properties. To show the remaining time using VariableValueDisplays, the seconds can also be counted in the Finite-State Machine.

  • FSM Variable increased or decreased with every tick:
ST_OtherRunning => ST_OtherRunning 
   {EV_TimerTickEverySecond: [V_SecondsLeft > 0] | set(V_SecondsLeft,V_SecondsLeft-1)}    

Task Initialization

The CBA ItemBuilder allows defining of multiple tasks within one project file. The underlying idea is that content should not be designed and duplicated several times in different files.

  • Tasks are defined using a Name and a Start Page in the Task Editor:
  • The Task-editor also contains a button Open, that opens an editor for the Task Initialization syntax.

  • Why? To configure Finite-State Machine settings (since the Finite-State Machine is shared across Tasks).

Task Initialization – Example

  • Imagine you want to create an item in an easy and a difficult version. The two versions differ in the time available, i.e. in the easy version the time limit should be 10 min., in the heavy version 7 min.
  • Task Initialization syntax (similar to Conditional Links) overwrites the Start Page.
  • Operator setFSMEvent() is used to define task-specific time for the Timed Event.
  • If a finite-state machine is used, then the same behavior can also be achieved with an operator in a task-specific start rule.

Operators to Trigger Events

Most often, FSM-events are either linked to user interactions (by linking vents to components) or events are triggered automatically (timed-events).

Events can also be triggered in syntax (either in Conditional Links or in Finite-State Machine rules).

Trigger Event in FSM-Transitions:

  • raise(EventName)

Trigger Events in Conditional Links:

  • initFSM(EventName)
  • The raise()-operator can be used to structure FSM-Syntax and to avoid identical syntax in multiple transitions.

Multipe (Nested) State-Machines

With one finite-state machine (FSM), one reaches limits when: a) Timed events are used, b) States are used for navigation, or c) the items become complex. The CBA ItemBuilder allows using several FSMs.

Implemented by

  • Nesting Finite-State Machines1

  • Use of multiple machines with Regions2

When creating multiple nested FSM’s, take care that states of one machine are on the same level.

Timed Events and Regions

Combination of Timers with Regions for Full Flexibility

  • Option A: Two timed events within one state (self-transition)

  • Option B: Two timed events within one state (internal)

  • Option C: Two timed events within Regions (internal)

Dynamically Change Finite-State Machines

Within the Task Initialization Syntax and as operators in Conditional Links the time assigned to events and the page link to states can be changed.

  • The setFSM()-operator can be used to change, for instance, Timed Events

Summary

Timed Events in FSMs:

  • Are defined by a simple number after the event name in the State Machine Rules syntax (e.g., Events: EV_t1 2.5, EV_t2 3600;).

  • Time is defined in seconds (i.e., EV_t1 is triggered aft 2.5 seconds, EV_t2 after 120 minutes).

  • Timed events are (re-)started on each State-entry.

    • ST_A internal {EV_A /* | ... */} will process event EV_A without re-starting the timers.
    • ST_A => ST_A {EV_A /* | ... */} will process event EV_A re-starting the timers!
  • Regions (i.e, nested Finite-State Machines) can be used to disentangle states (i.e., to create dedicated states, for instance, for Task-level time limits).

  • Components of type Timer (can be added to pages in the Page Editor) can show the remaining time (unit a Timed Event will trigger again).

Helpful to remember

  • Pages can be linked to States to allow flexible navigation schemes.
  • Timed events can be defined in the Finite-State Machine Syntax.
  • Multiple nested Finite-State Machines are supported.