Skip to main content

Speech

Provides functions for controlling speech and dialogue on NPCs.

info

This module can only be used in Entity scripts.

Functions

setText(text)

Sets the text displayed in a speech bubble.

Parameters

  • text The text value to display.

Example

Set a welcome message on a NPC.

function onStart()
Speech.setText('Welcome!')
end

clearText()

Clears the text displayed in a speech bubble.

Example

Clear a message after 5 seconds.

function onStart()
Speech.setText("This message is going to disappear in 5 seconds!")
Task.wait(5)
Speech.clearText()
end

prompt(text, options)

Sets the text and response options displayed in the dialogue prompt that is shown when a player interacts with the NPC.

Parameters

  • text The text value to display.
  • options A list of options displayed that the player can select to respond.

Returns

An integer representing the response option selected by the player, or nil if the prompt was closed.

Example

A simple interaction between a player and a NPC.

function onInteractStart(player)
-- Show a prompt when the player interacts with this NPC
local response = Speech.prompt('How are you today?', {
'Good!',
'Fine.',
'Terrible...',
})

-- Show another prompt depending on the option the player selected
if response == 0 then
Speech.prompt('Great!')
elseif response == 1 then
Speech.prompt('OK!')
elseif response == 2 then
Speech.prompt('Oh no!')
end
end

closePrompt()

Closes the dialogue prompt.

Example

Close a dialogue prompt after a short dialogue.

function onInteractStart(clientId)
-- Set our camera to dialogue and prevent player movement
Controls.setControlScheme(clientId, ControlScheme.Dialogue, false)

Speech.prompt("Welcome to my world, I hope you have a nice experience!")
Speech.closePrompt()
end

setName(name)

Sets the name of the NPC, displayed in the dialogue prompt.

Example

Set the name of a NPC to Gary.

function onStart()
Speech.setName("Gary")
end

function onInteractStart(clientId)
Speech.prompt("Hello, my name is Gary")
end