Simulation scripts play the central role in a simulation, and are only executed while a simulation is running. There are two types of simulation scripts:
The main script: by default, each scene has a main script that handles all the functionality (that is in charge of calling child scripts (see hereafter)). Without main script, a simulation cannot run. The main script can be customized, but it is preferable to do all the customization work in child scripts.
Child scripts: each scene object can be associated with a child script that can handle a specific part of a simulation. The most common use for a child script is to have it control a model (e.g. a robot). Since child scripts are attached to scene objects (i.e. they are associated scripts), they will also be duplicated during a copy-and-paste operation, which is an important feature that allows a simulation scene to be easily scalable. Associated scripts form the basis of CoppeliaSim's distributed control architecture.
Following are the main differences between the main script and a child script:
there can only be one main script. There can be an unlimited number of child scripts.
the main script is independent and should preferably not be customized. Child scripts are associated with scene objects and should be customized.
the main script is never duplicated in a copy/paste operation of scene objects. Child scripts will duplicate themselves together with their associated scene object.
child scripts support a few more callback functions than the main script.
Simulation scripts, and all scripts in general, are mainly invoked via system callback functions by CoppeliaSim, and follow a precise execution order in relation with other script types. They can run threaded or non-threaded.