Thread (scripting)

A script thread is the line of execution managed by the game code by the game class idThread.

It is typically created for a script function call from game code and deleted when that function exits.

A new thread is created when calling a function from within script via an entity reference to execute that function.

When an entity spawns with a script object set it will create a thread to execute the init() function.

spawn classes with FSMs manage a thread for the current set state, running it each frame.

The sys identifier is used within a script to call events defined on the game class idThread, they are called on the idThread instance that is executing that part of the script. See System Events for respective game: Script events .

Threads can be created from within a script itself by using the thread identifier. There are also several events for managing threads from within script. See Scripting basics#Threads .


Since threads are part of normal game execution, script authors using threads (including script objects ) to set up run time behavior must take note of letting threads execute for a long time without letting threads wait. Essentially letting the overall game execution continue.

Waiting suspends execution on the thread until the specified time.

While there is infinite loop protection, and a limit on events per frame, there may be other cases it won’t catch and run time behavior should be planned accordingly.