INSA
  • Tutorials
  • Documentation
  • Api Documentation
  • Changelog
Show / Hide Table of Contents
  • Getting Started
    • Quickstart
  • Unity tutorial
    • Introduction
    • Time for practice
    • Restricted scenario by script?
    • How to create the tutorial scene?
  • Scenario
    • How to create a sensor?
    • How to create an effector?
    • How to setup the engine?
    • How to edit a scenario?
    • How to run a scenario?
    • How to?
  • Relation engine
    • How to create a type?
    • How to create a relation?
    • What are queries? How do queries work?
    • How to be notified when a relation is executed?
  • Highlight Manager
    • How to create a Highlight?

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.

  1. Start by opening the ListenerScenario scene and then the current scenario in the Scenario editor.
Practice step 1
  1. 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.
Practice step 2
  1. 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).
Practice step 3
  1. 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.
Practice step 4
Note

SequenceContext gives access to the data inside the token. In this case, we created data using the TokenAssign function in step 3.

  1. 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.
Practice step 5
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

  1. 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
INSA     IRISA     Inria     Ouest Valorisation Back to top