The Dialogue System can tie into Inkle's Ink Integration for Unity.
Ink copyright © Inkle Studios.
Ink is a narrative scripting language created by Inkle Studios. You can read about Ink here:
https://www.inklestudios.com/ink/
Unlike the other third party file formats that use the Dialogue System's in-editor import tools to create dialogue databases, when working with Ink the Dialogue System uses Ink as the engine that parses Ink files and runs them. Your Ink files can use the Dialogue System's ShowAlert and quest control functions, and the Dialogue System can get and set Ink global variable values.
The example scene lets you play two conversations.
Add a Dialogue System Ink Integration component to the Dialogue Manager.
You may want to add the following to the database:
Note: Previous versions of this integration used a third actor for the player speaker. This is no longer necessary. Player lines are now assigned to the player actor.
If you tick the Dialogue System Ink Integration's Actor Names Precede Lines checkbox, you can specify actor names at the beginning of lines, separated by a colon, as in:
Monsieur Fogg: 'A wager,' he replied.
You can use all of the Dialogue System's regular triggers, scripting API calls, and visual scripting actions to start Ink stories as conversations.
Since the stories are added at runtime, you'll need to enter their names manually in Dialogue System Triggers' Conversation title field. Or, if you prefer, you can create a dummy database containing empty conversations with the same titles as your stories, assign this database to your Dialogue System Trigger's Reference Database, and select the conversation from the dropdown menu. (Don't add this dummy database to the Dialogue Manager.) The Reference Database is not used at runtime; it's used only to populate the dropdowns in the editor.
Note: This integration is designed to run one Ink story (conversation) at a time. You can run other, non-Ink conversations simultaneously with an Ink conversation, however.
If you want to start a conversation at a specific knot or a stitch within a knot, add a DIalogue System Ink Trigger component. This component is like the regular Dialogue System Trigger except it has an Ink-Specific section that lets you specify an optional knot (or knot.stitch) to start at.
To start a conversation manually, call DialogueManager.StartConversation as usual. If you want to start a conversation at a specific knot or stitch, call DialogueSystemInkIntegration.SetConversationStartingPoint("knot") first. For example:
The property DialogueManager.lastConversationStarted returns the name of the last conversation/Ink story started. Similarly, DialogueSystemInkIntegration.lastStartingPoint returns the knot that the last conversation started at. If the conversation started at the beginning of the story, lastStartingPoint will be blank.
Use a Dialogue System Ink Trigger component to start a bark. In the Ink-Specific section, specify the knot (or knot.stitch) to bark.
Alternatively, you can use a Bark Ink On Idle component to bark from an Ink story. In the Ink-Specific section, specify the knot (or knot.stitch) to bark. Note:
For any given line, to specify the actor (speaker) or conversant (listener), use Actor=actorName and/or Conversant=actorName tags. For example, to make the actor Boromir speak a line to the conversant Elrond:
- One does not simply walk into Mordor. # Actor=Boromir # Conversant=Elrond
You can also tick the integration's Actor Names Precede Lines checkbox to specify that the actor name appears at the beginning of the line, separated by a colon:
- Boromir: One does not simply walk into Mordor. # Conversant=Elrond
To make Dialogue System functions available to your Ink story, the Dialogue System integration will automatically register these external functions if you include the definitions below to the top of your Ink file at runtime:
EXTERNAL ShowAlert(x) // ShowAlert("message"): Shows an alert message. EXTERNAL Sequence(x) // Sequence("sequence"): Plays sequencer commands in string x. Note: Use [[x]] instead of {{x}} for shortcuts and => instead of -> to send messages. EXTERNAL CurrentQuestState(x) // CurrentQuestState("quest"): Returns the current quest state. EXTERNAL CurrentQuestEntryState(x,y) // CurrentQuestEntryState("quest", entry#): Returns the current quest entry state. EXTERNAL SetQuestState(x,y) // SetQuestState("quest", "inactive|active|success|failure"): Sets a quest state. EXTERNAL SetQuestEntryState(x,y,z) // SetQuestEntryState("quest", entry#, "inactive|active|success|failure"): Sets a quest entry state. EXTERNAL GetBoolVariable(x) // Returns the bool value of Dialogue System variable x. EXTERNAL GetIntVariable(x) // Returns the int value of Dialogue System variable x. EXTERNAL GetStringVariable(x) // Returns the string value of Dialogue System variable x. EXTERNAL SetBoolVariable(x,y) // Sets Dialogue System variable x to value of bool y. EXTERNAL SetIntVariable(x,y) // Sets Dialogue System variable x to value of int y. EXTERNAL SetStringVariable(x,y) // Sets Dialogue System variable x to value of string y. EXTERNAL Lua(x) // Runs Lua code x and returns the result as a string.
You may also want to add these fallback functions at the bottom of your file so you can test your story outside of the Dialogue System:
// Fallback functions == function ShowAlert(x) == ~ return 1 == function Sequence(x) == ~ return 1 == function CurrentQuestState(x) == ~ return "inactive" == function CurrentQuestEntryState(x,y) == ~ return "inactive" == function SetQuestState(x,y) == ~ return 1 == function SetQuestEntryState(x,y,z) == ~ return 1 == function GetBoolVariable(x) == ~ return false == function GetIntVariable(x) == ~ return 1 == function GetStringVariable(x) == ~ return "" == function SetBoolVariable(x,y) == ~ return 1 == function SetIntVariable(x,y) == ~ return 1 == function SetStringVariable(x,y) == ~ return 1 == function Lua(x) == ~ return ""
These functions are available in the Dialogue System's Lua environment:
Function | Description | Example |
---|---|---|
SetInkBool("variable", value) | Sets a Boolean value in your Ink stories. | SetInkBool("teacup", true) |
SetInkNumber("variable", value) | Sets a number value in your Ink stories. | SetInkNumber("wagerAmount", 16000) |
SetInkString("variable", "value") | Sets a string value in your Ink stories. | SetInkString("surname", "Shortshanks") |
SetInkList("variable", "value") | Sets a string value in your Ink stories. | SetInkList("kettleState", "cold") |
GetInkBool("variable") | Gets a Boolean value from your Ink stories. | GetInkBool("teacup") |
GetInkNumber("variable") | Gets a number value from your Ink stories. | GetInkNumber("wagerAmount") |
GetInkString("variable") | Gets a string value from your Ink stories. | GetInkString("surname") |
GetInkList("variable") | Gets a list value from your Ink stories. | GetInkList("kettleState") |
DialogueSystemInkIntegration.instance.GetActorsInStory(string storyName, string knot)
This function returns a string[] array of actor names that appear in #Actor=XXX and #Conversant=XXX tags as well as actor names preceding lines (e.g., "Bob: Hi, I'm Bob.") if Actor Names Precede Lines is ticked.
If knot
is blank, it processes the entire story.
Notes:
InkEntrypoint.FromString(string s)
Returns an InkEntrypoint object (containing 3 strings: story, knot, and stitch) from a string of any of these formats:
The corresponding InkEntrypoint.ToString() method returns the string representation of an InkEntrypoint object.
[InkEntrypoint] Attribute
You can add the [InkEntrypoint]
attribute to a public string variable in your scripts to show the variable in the inspector as a dropdown from which you can select stories, knots, and stitches.