It is also possible to 'thread' from another script in the same way
As far as I know there is only a very subtle difference between 'thread' and 'exec', which is only apparent when calling threads within the same file. 'exec' creates a new thread group, whereas 'thread' expands the current thread group, provided it is posted as an event for the current thread ('local') and not as an event for a specific listener.
I realize that sentence may not make a lot of sense so I'll try a more illustrative approach. First some defs
A thread group is just a bunch of threads (processes) which are bundled internally by the script interpreter. Usually the concept is unimportant for scripting unless you are using the 'group' object to store variables, since this requires the threads you want to share variables to belong to the same thread group.
Thread groups may be created when new threads start and may be destroyed when all of its threads have ended.
Individual threads in a thread group always belong to the same 'physical' script file (.scr).
Now it is important to take a closer look at how threads may be started. There are a couple of options:
- thread somethread
- thread somescript::somethread
- someobject thread somethread
- someobject thread somescript::somethread
- exec somescript
- exec somescript::somethread
- someobject exec somescript
- someobject exec somescript::somethread
Additionally, there are also waitthread / waitexec variants which I will discuss in a moment.
Option 1 is the only option that will gently expand the current thread group. All other options will lead to new thread groups being created.
Note that 'someobject' includes entities ('$door thread do_this'), self ('self thread do_that'), or any other listeners.
For waitthread/waitexec the situation is similar, only 'waitthread somethread' preserves thread group.
So the difference between 'thread' and 'exec':
thread may maintain thread group, exec never does
There is also another difference between 'waitthread' and 'waitexec':
waitthread waits for the thread to finish, waitexec waits for the entire thread group to finish. The results of this may be quite unexpected and I therefore advise always to use waitthread instead of waitexec.
This ought to help
