Core API¶
This page documents the core functionality of SimpleDialogue.
SimpleDialogue¶
The main module that provides dialogue creation and management capabilities.
Methods¶
SimpleDialogue.new(model)
¶
Creates a new dialogue controller attached to the specified model.
Parameters:
- model
: The NPC model (Instance)
Returns: - A dialogue controller instance
Example:
SimpleDialogue.CreateNode(text, options)
¶
Creates a dialogue node with the specified text and options.
Parameters:
-
text
: The NPC's dialogue text (string) -
options
: Array of options created withSimpleDialogue.CreateOption()
Returns: - A dialogue node object
Example:
local node = SimpleDialogue.CreateNode("Hello! How can I help you?", {
SimpleDialogue.CreateOption("Option 1", callback),
SimpleDialogue.CreateOption("Option 2", callback)
})
SimpleDialogue.CreateAutoNode(text, callback, shouldEndDialogue)
¶
Creates a dialogue node with the specified text and options.
Parameters:
-
text
: The NPC's dialogue text (string) -
callback
: Function to call when the dialogue text is fully shown. -
shouldEndDialogue
: A boolean to let the controller know whether if it should automatically end the dialogue after the callback has been ran.
Returns: - A dialogue node object
Example:
local node = SimpleDialogue.CreateAutoNode("Hello! How can I help you?", function()
task.spawn(5)
dialogue:EndDialogue()
end, false)
SimpleDialogue.CreateOption(text, callback, next, displayText)
¶
Creates a dialogue option for a node.
Parameters:
-
text
: The text displayed for this option (string) -
callback
: Function to call when this option is selected (function, optional) -
next
: Index of the next node to display, or -1 to end dialogue (number, optional, defaults to -1) -
displayText
: Text to display from the NPC after selecting this option (string, optional)
Returns: - A dialogue option object
Example:
local option = SimpleDialogue.CreateOption("Tell me more", function()
print("Player chose to learn more")
end, 2, "I'm glad you're interested!")
SimpleDialogue.CreateTree(nodes)
¶
Creates a complete dialogue tree from a collection of nodes.
Parameters:
nodes
: Array of dialogue nodes created withSimpleDialogue.CreateNode()
, andSimpleDialogue.CreateAutoNode()
Returns: - A dialogue tree object
Example:
local dialogueTree = SimpleDialogue.CreateTree({
SimpleDialogue.CreateNode("Hello!", options1),
SimpleDialogue.CreateNode("More information", options2)
})
Instance Methods¶
Methods available on dialogue controller instances:
:SetDialogueTree(tree)
¶
Sets the dialogue tree for this controller.
Parameters:
tree
: A dialogue tree created withSimpleDialogue.CreateTree()
Example:
:SetConfiguration(config)
¶
Configures the dialogue system settings.
Parameters:
-
config
: Configuration table with the following options: -
textSpeed
: Speed of text typing effect (number) -
autoAdvance
: Whether dialogue auto-advances (boolean) -
proximityDistance
: Maximum player distance before dialogue ends (number) -
offsetDistance
: UI offset distance (number) -
Various visual customization options
Example:
:DisplayNode(node)
¶
Displays a specific dialogue node.
Parameters:
node
: A dialogue node from the tree, either a node instance or specific number
Example:
dialogue:DisplayNode(dialogueTree[2]) -- Display the second node
dialogue:DisplayNode(4) -- Display the fourth node
:ShowNPCText(text, callback)
¶
Shows a message from the NPC with a typing effect.
Parameters:
-
text
: Message text to display -
callback
: Function to call when text is fully displayed (optional)
Example:
dialogue:ShowNPCText("This is important information!", function()
print("Text displayed fully")
end)
:ShowPlayerText(text)
¶
Shows text above the player's character.
Parameters:
text
: Text to display above the player
Example:
:EndDialogue()
¶
Ends the current dialogue interaction.
Example:
:SetOnInteract(callback)
¶
Sets a callback to run when dialogue begins.
Parameters:
callback
: Function to call when dialogue starts
Example:
:SetOnOptionSelected(callback)
¶
Sets a callback to run when a dialogue option is selected.
Parameters:
callback
: Function to call with the selected option
Example:
:SetOnDialogueEnd(callback)
¶
Sets a callback to run when dialogue ends.
Parameters:
callback
: Function to call when dialogue ends
Example:
:Destroy()
¶
Cleans up the dialogue controller and removes event connections.
Example: