Time for practice
Now that we have seen how virtual environments and scenarios can work together, we will see how to improve an existing scenario. This section requires that you are familiar with the core concepts of scenarios. Report to the Scenario Engine section for a description of those concepts.
You will create a loop in the existing scenario that will count how many times the token has passed through the loop and if it reaches a threshold, the scenario will finish. We will use the scenario editor. You can find a short FAQ on how to use it here and how to edit a scenario here.
- Start by opening the ListenerScenario scene and then the current scenario in the Scenario editor.
- Create the loop by starting an arc between Place_2 and Place_4. It will create a transition between them, and then move it on the side by dragging it with left click. Make sure that the arrows are well oriented.
- Initialize a variable that will count number of times the token passes through the loop. To do so, we will add a Xareus.Scenarios.TokenAssign function in the transition Red Cube just before the loop. Select Extra.DefaultTokenUpdate, check the TokenData box to add data, create a new variable using the new button and name it count, then assign it an initial value (you can optionaly change the data type to int) and select the downstream sequences (you can select all).
- Now we can use our count variable in the loop. Return to the transition you added (you can change the label to 'Colored Textured Cube' in the editor). We need a Arithmetics.NumberEffector that will increment the value of count each time the token passes through this transition.
Note
SequenceContext gives access to the data inside the token. In this case, we created data using the TokenAssign function in step 3.
- Now we just need to check if the value count that we increment has reached a certain value. Start an arc between Place_4 and Place_3 and add a Arithmetics.NumberSensor that will check our variable's value. Compare count with the threshold value you wish it loops before the scenario finishes.
Note
You could even delete the last transition 'Green Cube', so the scenario does not end before it reach the number of looping.
Note
To ensure the 'Colored Textured Cube' transition is validated before the 'Green Cube' one, you can also give it a higher priority value
- Last step, save your scenario (as a new scenario or overwrite it) and play the scene. Make sure the button Play Mode is pressed in the Scenario editor, so that you can see your scenario running. Note that while the cubes colors will change, their names won't