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

Properties inherited from ModelProperties inherited from PVInstance

Methods

Methods inherited from ModelMethods inherited from PVInstance

Properties

Methods

BindToMessage

Write Parallel

This method is used to bind a Luau callback to a message with the specified topic. When a message is sent (using 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.

Default Value: ""
function: function
Default Value: ""

Returns

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

BindToMessageParallel

Write Parallel

This method is used to bind a Luau callback to a message with the specified topic. When a message is sent (using 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.

Default Value: ""
function: function
Default Value: ""

Returns

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

SendMessage

()
Write Parallel

Sends a message to an Actor. Messages are sent asynchronously, so the sender will not block or yield when calling the 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 BindToMessage() for details on receiving a message sent using 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.

Default Value: ""
message: Tuple

The contents of the message to send to the Actor.

Default Value: ""

Returns

()

Events