Navigation:  Examples >

Example 2: Branching the Work Flow

Previous pageReturn to chapter overviewNext page

Example 2: Branching the Work flow

Run This Example in New Window

In previous example, the work flow is very straightforward: when event happens, execute an action.  Now let's make it a little complex: branch the work flow and let user to decide which branch to go.

Just like what we did in previous example: add a button element into the plot, open behavior editor, define a behavior for the button, and add the "Element Clicked" event.

example02_button_event

Click the "Add Flow Control" button in the toolbar and then choose the "User Decision Branching..." in the pop-up menu.

example02_add_branch

In the popup window,  input the question that will prompt user: "Do you know my location?".

example02_ask_user

Select the "Yes" node in behavior editor and click the "Add Action" button to add a "Show Message" action.

example02_add_message

Here we input a praising message: "Ok, you are genius!"

example02_show_message1

Select the "No" node, and click the "Add Action" button to add a "Show Message" action.

example02_add_message2

In the "Show Message" edit window, we click the add_property_button button to insert two element properties to represent the current location of the button.

example02_add_properties

You will be asked to choose an element to provide the property, we choose Button_1.

example02_choose_prop_owner

Then in the property chooser window, we can find the property that represent the X coordinate of Button_1.

example02_insert_x

The inserted element property looks like this:

example02_inserted_prop

We can do the same thing for inserting another property that represent the Y coordinate of Button_1, and complete the message by adding a few words:

example02_completed_message

The final behavior for Button_1 should looks like:

example02_final

Now you can run the simulation by clicking the run-sim button in the toolbar of main window.  This example shows how the branching works and the ability to access the element property. You can view this online example to see the result, or download the plot file.

In this example we use the "User Decision Branching", which can branch the work flow according user's decision. ForeUI also support another two types of branching:

Conditional Branching: do branching according to the conditions.
Switch Branching: do branching according to the value of expression.

Please read the Branching section for more details.