Roblox Guide Help

Dialogue Module

In your wally.toml file, add this to your dependencies:

[dependencies] dialogue-module = "release/dialogue-module@0.0.3"

You have two solutions to import this module, depending if you wish to import the Controller or the Service on your own, or if you let the module give you the right code.

local DialogueModule = require(ReplicatedStorage.Packages["dialogue-module"])
local DialogueController = Knit.GetService("DialogueController")

A file called DialogueModule.config.lua is to be created in the folder ReplicatedStorage/Shared/Configs.

return table.freeze({ ["Welcome_NPCTemplate"] = { texts = {"Hello sir!", "I need 3 carrots !"}, answers = { [1] = { prompt = "How are you ?", texts = {"Doing excellent, thank you !"}, answers = { [1] = { prompt = "Can I help you?", texts = {"I need 3 carrots !"}, action = function() print("go get 3 carrots!") end }, [2] = { prompt = "Goodbye !", texts = {"Goodbye !"}, action = nil }, }, }, [2] = { prompt = "Goodbye !", texts = {"Goodbye !"}, action = nil }, }, action = function() print(game.Players.LocalPlayer.Name) end, }, })

Explanation: Each indexed table represent a dialogue node. A dialogue node contains:

  • texts: An array of texts to be displayed when the dialogue triggers.

  • answers: A table of nodes.

  • action: A callback to perform actions once the dialogue is triggered (precise dialogues events will be added in the next update)

  • prompt: Optional string to be displayed as the player’s answer in dialogues answers. (The text that will trigger the dialogue)

Usage

Methods

Client

DialogueController:GetDialogue(dialogueName: string): {}

Explanation

  • dialogueName: The dialogue to fetch.

local dialogue = DialogueController:GetDialogue("Welcome_Tutorial") print(dialogue.texts[1])

    Client

    DialogueController:GetAllTextsFromNode(node: table): {}

    Explanation

    • node: The dialogue to fetch from.

    local dialogue = DialogueController:GetDialogue("Welcome_Tutorial") local texts = DialogueController:GetAllTextsFromNode(dialogue) print(texts[1])

      Client

      DialogueController:GetAllAnswersFromNode(node: table): {}

      Explanation

      • node: The dialogue to fetch from.

      local dialogue = DialogueController:GetDialogue("Welcome_Tutorial") local answers = DialogueController:GetAllAnswersFromNode(dialogue) local answersTexts = DialogueController:GetAllTextsFromNode(answers) print(answersTexts[1])

        Client

        DialogueController:ExecuteAction(node: table): any

        Explanation

        • node: The dialogue to perform the action of.

        This will execute the callback action given from the config.

        local dialogue = DialogueController:GetDialogue("Welcome_Tutorial") DialogueController:ExecuteAction(dialogue)
          Last modified: 28 November 2024