util.thread.create

Shared

Creates a new thread instance with specified function in suspended state


Syntax

local instance = util.thread.create(
    exec
)

Parameters

TypeNameDescription
functionexecFunction to execute by the thread

Returns

TypeNameDescription
thread | boolinstanceCreated thread instance on successful execution, false otherwise

Callback: exec

exec(self)
TypeNameDescription
threadselfRunning thread instance

Examples

Create and resume a basic thread
local entity = util.thread.create(function(self)
    core.engine.print("info", "Hello from thread")
end)

entity:resume()
Create a thread and sleep inside it
local entity = util.thread.create(function(self)
    core.engine.print("info", "Sleeping for 2 seconds")
    self:sleep(2000)
    core.engine.print("info", "Awake now")
end)

entity:resume()

On this page