Script calling methodologyScripts are called from the default main client application (vrep.exe) when a simulation is running. The main client application calls the simHandleMainScript API function, which executes the main script of the current scene. From there, it is the responsibility of the main script to execute child scripts. Child script execution is handled with one single API command: simHandleChildScript. If you refer to the section on child scripts, you will notice that every child script is associated with a scene object. This is not the case for the main script that is not associated with any object. To help understand following, consider for a moment the main script associated with an imaginary scene object named "world", which is the parent of all parentless objects in the scene. Following figure illustrates this idea: [Main script and child scripts in a scene] The command simHandleChildScript(sim_handle_all), when called from the main script, will execute all first encountered child scripts when exploring its tree hierarchy, i.e. it will call child scripts in a cascaded way. In above example, a simHandleChildScript command called from the main script will execute 3 child scripts: the ones that are associated with object3, object4 and object7. The child script associated with object6 will not be executed by that command, since it is the responsibility of the child script associated with object3 to handle its own child scripts (i.e. the child scripts built on its tree hierarchy). This means that the child script associated with object6 will only be executed if the child script associated with object3 also calls simHandleChildScript(sim_handle_all). In short, remember following: it is each script's responsibility to execute (or to delegate execution of) the child scripts in its tree hierarchy. Execution happens in a cascaded way. Child scripts that launch a thread can delegate their child script execution to the main script with the simDelegateChildScriptExecution command. This is the default behavior of threaded child scripts. This script execution mechanism makes the handling of newly added (e.g. copy/pasted) objects or models very easy, since associated child scripts will automatically be executed, without having to modify/edit any code. Following figures illustrate the script exploration and calling performed by the main client application during a simulation: [Application loop (main client application), main script and child scripts] [Exploration and execution route of above's example (threaded child scripts are in light blue)] Notice how child script 5 and child script 6 don't get executed because child script 4 doesn't call simHandleChildScript(sim_handle_all). Recommended topics |