Script dialog

The script dialog is located at [Menu bar --> Tools --> Scripts]. Alternatively, it can also be accessed through its toolbar button:

[Script toolbar button]


[Script dialog]


  • Insert new script: allows adding new scripts. Three types can be chosen from: main script, non-threaded child script, or threaded child script. Remember that there cannot be more than one main script. Child scripts can also be added by selecting an object in the scene, then clicking [Menu bar --> Add --> Associated child script --> Non-threaded] or [Menu bar --> Add --> Associated child script --> Threaded]. Callback scripts can be added via the dynamic joint properties dialog, or via the environment dialog. Add-on scripts are loaded at application start.
  • Script listing: all scripts that are loaded. Scripts can be removed by using the delete-key. A double-click opens the script in the script editor. A script can also be opened with a double-click on a script icon in the scene hierarchy.
  • Explicit handling: indicates whether execution of a child script should be explicitly handled. If checked, then the script won't be executed when simHandleChildScript(sim_handle_all_except_explicit) is called, but only if simHandleChildScript(sim_handle_all) or simHandleChildScript(scriptHandle) is called. This is useful if the user wishes to handle the script execution privately. Refer also to the section on explicit and non-explicit calls.
  • Script launches a new thread: if this item is enabled, then next time the selected child script will be called, it will execute itself in a thread (the call will start a new thread and directly return). A subsequent call to that child script will launch another thread only if previous thread ended.
  • Execute just once: by default, all scripts will be executed as many times as they are called. Selecting this item limits the number of execution passes to one at maximum. While this could also be handled with a few simple instructions inside a non-threaded child script, threaded child scripts do not allow this: indeed, every time the thread is (re-)launched, the Lua state for that script is re-initialized (i.e. all variables are cleared).
  • Execute in the sensing phase: this option, only available for non-threaded and non-explicitely handled child scripts, when enabled, informs the main script to execute the selected child script AFTER all actuation was performed. Refer to the section on main scripts and to the simHandleSensingChildScripts command for more details.
  • Associated object: object that is currently associated with the script.
  • Execution order: specifies the execution order for a group of child scripts. The API command simHandleChildScript(sim_handle_all) or simHandleChildScript(sim_handle_all_except_explicit) will call (execute) all first child scripts built on the hierarchy in a random order, and most of the time this works fine. In rare cases it is however necessary to make sure one child script gets executed before or after another in order to have a good synchronization (e.g. if child script 2 is waiting for a signal from child script 1, then child script 1 should preferably be executed first (otherwise the signal will be received by child script 2 only in the next simulation pass (one simulation time step later))). If you require more than 3 execution order categories, then you should explicitely handle the related child scripts.

  • Recommended topics

  • The main script
  • Child scripts
  • Callback scripts
  • Add-on scripts
  • Script editor