Actor
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.
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
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
Returns
This connection object may be used to disconnect the Luau callback from receiving messages.
SendMessage
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 instanceactor:SendMessage("Greeting", "Hello World")
Parameters
The topic used to identify the message being sent.
The contents of the message to send to the Actor.