How can I monitor and change the state of an object with a variable?

Use a variable to monitor and change the state of an object that has a behaviour model.

At times it is necessary to be able to check the state of an object before the learner can take action on it. For instance, if we want the learner to remove a machine part, we need to first check that it is unfastened. If it isn't, we can prompt the learner that they need to take some action.

If a 3D asset has a behaviour model, it has a built-in set of states that are tracked. In order to be able to check these states using conditions and to change these states during the scenario (without user interaction) we need to create a variable and bind it to the behaviour model.

Let's take a look at how that is done:

Step 1: Create a Variable

In this example, we have a behaviour model for a screw. It relies on a boolean (true or false) to determine if it is fastened. The behaviour model looks like this:

Create a variable that is the same type (in this case boolean) with a descriptive name (in this case "Screw Fastened"). Note that we make the variable global so that we can use it in other scripts:

make a variable for BH

Step 2: Bind the Variable to the Behaviour Model

Next we need the have the behaviour model for the screw dictate the value of the variable we just created (and vice versa). We accomplish this by using a "Behaviour Model" resource:

Select the scene objects you would like to monitor, the associated behaviour model and the variable you just created:

How can I use this?

There are two ways that this is useful:

  1. You can now check the status of the screw using a variable comparison condition:
    This says "If the screw is fastened, proceed with the contents of this frame"
  2. You can also set the value of the variable in a frame to change the state of the screw without needing user interaction:
    use a bh variable to change state

Note: If you somehow close the script where you have set up this behaviour model binding, it will no longer work! So make sure you don't use an "End script" resource here!