Vrep脚本的执行顺序

具体情况看这个答案:

 Problems about simulation loop - V-REP Forum 

 http://www.forum.coppeliarobotics.com/viewtopic.php?f=9&t=5856&p=23502&hilit=cascaded+order#p23502

Vrep 中non-threaded child scripts的执行顺序是未知的但是可以人为指定。

1.使用Scirpt toolbar button

Vrep脚本的执行顺序

Execution order: specifies the execution order for a scripts. The execution order only has an effect on scripts located on similar hierarchy level.You can set the execution priority or order for child script in the script dialog. This will however have an effect only if the two scripts are either both threaded or both non-threaded. On top of that, if your first script is built on the hierarchy of the second script, then will will not work either, because scripts are executed in a cascaded fashion (i.e. cascaded order: first the main script will execute. The main script will then first launch the threaded child scripts in a cascaded fashion (with simLaunchThreadedChildScripts), then the non-threaded child scripts (also in a cascaded fashion, with simHandleChildScripts).

2.使用sim.switchThread()                                                                                                                                                                          

Description Allows specifying the exact moment at which the current thread should switch to another thread. If the current script doesn't run in a thread (i.e. if it runs in the application main thread), this function has no effect. By default, V-REP doesn't use "regular" threads, but something similar to hybrid threads (which behave like coroutines, but can also behave like regular threads). This allows much more flexibility and execution control of the threads: each thread (except for the main or application thread) has a switch timing associated, which specifies how long the thread will run before switching to other threads. By default this value is 2 millisecond, but can be modified with sim.setThreadSwitchTiming. That timing can be shortened with sim.switchThread. Use with care when calling this function from a plugin. See also the sim.setThreadAutomaticSwitchsim.setThreadResumeLocation and sim.setThreadIsFree functions.
Lua return values
result: 1 if the thread was switched (the current thread gave control to other threads until the next calculation pass), 0 if it was not switched (e.g. because the function was called from the main or application thread), or -1 in case of an error.