Actor

Show Deprecated

An Actor is a container for code that can be safely split into its own thread using task.desynchronize(). It should also contain the instances used by its scripts.

To learn more about using multiple Actors to optimize script performance, see Parallel Luau.

Summary

Properties

Methods


Binds a Luau callback to a message with the specified topic.


Binds a Luau callback to a message with the specified topic.

SendMessage(topic: string, message: Tuple): void  

Sends a message to an Actor.

Events

Properties

Methods

BindToMessage

This method is used to bind a Luau callback to a message with the specified topic. When a message is sent (using Actor/SendMessage) to the topic specified the provided callback will be called in a serial execution context.

Multiple Luau callbacks may be bound to a single actor and even to a single message topic.

Note: Only the scripts which are descendants of an Actor may bind to its messages.


local actor = script:GetActor()
-- Print out a message when a greeting message is sent to the Actor
-- this script is a descendant of.
local connection = actor:BindToMessage("Greeting", function(message)
print("Received Greeting Message:", message)
end)

Parameters

topic: string

The topic used to identify the type of message.

function: function

Returns

This connection object may be used to disconnect the Luau callback from receiving messages.

BindToMessageParallel

This method is used to bind a Luau callback to a message with the specified topic. When a message is sent (using Actor/SendMessage) to the topic specified the provided callback will be called in a parallel execution context.

Multiple Luau callbacks may be bound to a single actor and even to a single message topic.

Note: Only the scripts which are descendants of an Actor may bind to its messages.


local actor = script:GetActor()
-- Print out a message when a greeting message is sent to the Actor
-- this script is a descendant of.
local connection = actor:BindToMessageParallel("Greeting", function(message)
print("Received Greeting Message:", message)
end)

Parameters

topic: string

The topic used to identify the type of message.

function: function

Returns

This connection object may be used to disconnect the Luau callback from receiving messages.

SendMessage

void

Sends a message to an Actor. Messages are sent asynchronously, so the sender will not block or yield when calling the Actor/SendMessage method.

Since a single Actor may receive different kinds of messages, a topic parameter is used to distinguish between various kinds of messages.

See Actor/BindToMessage for details on receiving a message sent using Actor/SendMessage.


-- Assume `actor` is a local variable referring to an Actor instance
actor:SendMessage("Greeting", "Hello World")

Parameters

topic: string

The topic used to identify the message being sent.

message: Tuple

The contents of the message to send to the Actor.


Returns

void

Events