Skip to content

Actors

The Actor library provides support for seamlessly running code within other global states.


getactors

function getactors(): table<number, Actor>

Returns a list of actors that you are able to execute code inside of.

Iterate through the list of actors and output them to the console.

for index, actor in getactors() do 
    print(index, actor)
end


run_on_actor

function run_on_actor(actor: Actor?, script: string, (opt) channel_data: any): ()
Runs the code specified inside of that actor's global state. The third argument of run_on_actor can anything, however you cannot pass types like tables and functions As they are from a different Lua VM

Execute a simple Hello World! print script inside of the first actor present. (not all games contain Actors)

run_on_actor(getactors()[1], 'print("Hello World!")')

Transfer a message between the actor global state and your state You cannot transfer certain data types (tables, functions, etc, due it being from a different Lua VM)

local comm_id, event = create_comm_channel()
event.Event:Connect(function(data)
    print(data) -- -> Hello World!
end)
run_on_actor(getactors()[1], [=[
    local channel = get_comm_channel(...)
    channel:Fire('print("Hello World!"')
]=], comm_id)


create_comm_channel

function create_comm_channel(): (number, BindableEvent)
Returns a communication id, and a bindable event that can be used for transferring data between the actor global state and your state

local comm_id, event = create_comm_channel()
warn(comm_id, event) -- <number>, BindableEvent

isparallel

function isparallel(): boolean
Returns a boolean dictating if the current thread is in parallel state

Prints whether or not the current lua state is in parallel phase.

print(if isparallel() then "In Parallel" else "Not In Parallel")

getactorthreads

Returns a list of threads that you are able to execute code inside of.

Iterate through the list of threads and output them to the console.

for index, thread in getactorthreads() do 
    print(index, thread)
end

run_on_thread

function run_on_thread(actor_thread: thread, string: string, (opt) channel_data: any) : ()

Run on the first actor thread present (not all games contain actors)

run_on_thread(getactorthreads()[1], "print('Hello World!')")