This page explains how to integrate ICode (formerly AI for Mecanim) and the Dialogue System. (ICode is required.)

ICode copyright © Zerano.


Introduction and Setup

The support package adds Dialogue System-specific actions and conditions, as well as Lua functions and sequencer commands to control ICode variables in Lua and sequences.

For general gameplay integration topics, see How to Integrate with Gameplay.

To set up support, import the package Third Party Support/ICode Support. This will unpack files into the folder Third Party Support/ICode.


Dialogue System State Machine Actions

The Dialogue System adds these state machine actions in the ICode support package:

Bark

Action Description
Bark Makes an NPC bark.

Conversation

Action Description
StartConversation Starts a conversation.
StopConversation Stops the active conversation
UpdateResponses Updates the choices in the response menu. If events can occur in your game while the response menu is active, and if those events can change what choices are available in the menu, then use this action after those events occur
GetIsConversationActive Checks if a conversation is active and stores the result in a bool parameter
Condition Description
IsConversationActive Checks if the Dialogue System is currently running a conversation
DoesConversationHaveValidDialogueEntries Checks if a conversation currently has any valid starting dialogue entries

Database

Action Description
AddDialogueDatabase Loads an extra database into the master dialogue database
PreloadMasterDatabase Loads the master dialogue database into memory. Normally this automatically happens the first time the database is needed. If your database is very large, you can preload it at a time of your choosing to prevent a hiccup in gameplay
RemoveDialogueDatabase Removes a database from the master dialogue database
ResetMasterDatabase Resets the master dialogue database to its initial state

Lua

Action Description
Lua Runs Lua code and stores the return value

More info: Lua

Variable

Action Description
GetBoolVariable Gets the value of a bool variable.
GetFloatVariable Gets the value of a float variable.
GetIntVariable Gets the value of an int variable.
GetStringVariable Gets the value of a string variable.
SetBoolVariable Sets the value of a bool variable.
SetFloatVariable Sets the value of a float variable.
SetIntVariable Sets the value of an int variable.
SetStringVariable Sets the value of a string variable.

Misc

Action Description
GetTime Gets the value of UnityEngine.Time.time

Quest

Action Description
GetQuestState Gets the state of a quest ("unassigned", "active", "success", or "failure")
SetQuestState Sets the state of a quest ("unassigned", "active", "success", or "failure")
GetQuestEntryState Gets the state of a quest entry ("unassigned", "active", "success", or "failure")
SetQuestEntryState Sets the state of a quest entry ("unassigned", "active", "success", or "failure")

Save System

Action Description
ApplyPersistentData Tells all persistent data components to retrieve their state from the Lua environment
ApplySavegameData Applies savegame data to the Lua environment and all persistent data components
BroadcastLevelWillBeUnloaded Tells all persistent data components that the level is about to be unloaded. Some persistent data components, such as PersistentDestructible, take action when they receive OnDestroy messages during gameplay. When loading a new level, the old level is destroyed, which also sends OnDestroy to all scene objects. This action tells the persistent data components to ignore the next OnDestroy. Use this action before changing levels
GetSavegameData Tells all persistent data components to store their state in the Lua environment, then gets the savegame data from the Lua environment. This data allows the Dialogue System and persistent data components to reconstruct their state when loading a game
RecordPersistentData Tells all persistent data components to record their state into the Lua environment
ResetPersistentData Tells all persistent data components to reset the state stored in the Lua environment

More info: Save System

Sequence

Action Description
PlaySequence Plays a cutscene sequence

More info: Sequences

Status and Relationships

Action Description
GetRelationship Gets a relationship value between two actors
GetStatus Gets the status value between two assets (usually two actors)
SetRelationship Sets a relationship value between two actors
SetStatus Sets the status value between two assets (usually two actors)

More info: Chat Mapper Functions


Lua Functions

You can use the following Lua functions in your dialogue entries' Conditions and Script fields to interface with ICode. To use them, add the ICodeLuaFunctions component to your Dialogue Manager GameObject.

GetStateBool(objectName, parameterName)

Description: Gets the value of a state machine's bool parameter.

Parameters:

  • objectName: The name of the object that owns the state machine.
  • parameterName: The name of a parameter in the state machine.

Example:: The example below gets the value of a parameter named "Randomize" on the NPC named "_Barker".

r = GetStateBool("_Barker", "Randomize")

GetStateFloat(objectName, parameterName)

Description: Gets the value of a state machine's float parameter.

Parameters:

  • objectName: The name of the object that owns the state machine.
  • parameterName: The name of a parameter in the state machine.

Example:: The example below gets the value of a parameter named "Bark Time" on the NPC named "_Barker".

bt = GetStateFloat("_Barker", "Bark Time")

GetStateInt(objectName, parameterName)

Description: Gets the value of a state machine's int parameter.

Parameters:

  • objectName: The name of the object that owns the state machine.
  • parameterName: The name of a parameter in the state machine.

Example:: The example below gets the value of a parameter named "Bark Index" on the NPC named "_Barker".

bi = GetStateInt("_Barker", "Bark Index")

GetStateObject(objectName, parameterName)

Description: Gets the value of a state machine's object parameter.

Parameters:

  • objectName: The name of the object that owns the state machine.
  • parameterName: The name of a parameter in the state machine.

Example:: The example below gets the name of a parameter value named "Conversant" on the NPC named "_Barker".

conversantName = GetStateObject("_Barker", "Conversant")

SetStateBool(objectName, parameterName, value)

Description: Sets the value of a state machine's bool parameter.

Parameters:

  • objectName: The name of the object that owns the state machine.
  • parameterName: The name of a parameter in the state machine.
  • value: The parameter's new value.

Example:: The example below sets the value of a parameter named "Randomize" on the NPC named "_Barker".

SetStateBool("_Barker", "Randomize", true)

SetStateFloat(objectName, parameterName, value)

Description: Sets the value of a state machine's float parameter.

Parameters:

  • objectName: The name of the object that owns the state machine.
  • parameterName: The name of a parameter in the state machine.
  • value: The parameter's new value.

Example:: The example below sets the value of a parameter named "Seconds Between Barks" on the NPC named "_Barker".

SetStateFloat("_Barker", "Seconds Between Barks", 9)

SetStateInt(objectName, parameterName, value)

Description: Sets the value of a state machine's int parameter.

Parameters:

  • objectName: The name of the object that owns the state machine.
  • parameterName: The name of a parameter in the state machine.
  • value: The parameter's new value.

Example:: The example below sets the value of a parameter named "Bark Index" on the NPC named "_Barker".

SetStateInt("_Barker", "Bark Index", 3)

GetStateObject(objectName, parameterName)

Description: Gets the value of a state machine's object parameter.

Parameters:

  • objectName: The name of the object that owns the state machine.
  • parameterName: The name of a parameter in the state machine.
  • value: The parameter's new value. This should be the name of an object.

Example:: The example below sets the value of a parameter named "Conversant" on the NPC named "_Barker" to an object named "Fred".

SetStateObject("_Barker", "Conversant", "Fred")

Sequencer Commands

You can use the following sequencer commands in your dialogue entries' Sequence field to interface with RPG Kit.

SetStateXXX()

Syntax:

  • SetStateBool(objectName, parameterName, value)
  • SetStateInt(objectName, parameterName, value)
  • SetStateFloat(objectName, parameterName, value)
  • SetStateObject(objectName, parameterName, value)

Description: Sets a parameter on a state machine.

Parameters:

  • objectName: The name of an object (usually a GameObject such as an NPC) that has a state machine. You can also use 'this' or 'speaker' for the speaker, or 'listener' for the listener.
  • parameterName: The name of a parameter in the state machine.
  • value: The new value.

Example:

  • SetStateBool(_Barker, Randomize, true) (Sets the "Randomize" parameter to true on the NPC named "_Barker")
  • SetStateInt(_Barker, Bark Index, 3) (Sets the "Bark Index" parameter to 3 on the NPC named "_Barker")

More info: Sequences


ICode Variable Trigger

You can use the ICode Variable Trigger component to set an ICode variable when a trigger event such as "OnUse" occurs. (Component > Dialogue System > Third Party Support > ICode > ICode Variable Trigger)

The ICode support example scene uses this to trigger state machine transitions when the player sends an NPC an "OnUse" message using the Selector.


<< Third Party Support