Actor Names / Items / Locations in Dialogue Text

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
SystemId
Posts: 30
Joined: Thu Aug 08, 2019 1:31 pm

Actor Names / Items / Locations in Dialogue Text

Post by SystemId »

I've been trying to find the best way to go about about displaying Actor Names (Or additional Fields), Locations names (or Additional fields) .. Variables .. variable values etc. in the Dialogue Text.

Example:
A Shop Keeper is asking the Player:

Welcome, (Rich Text Bold)(Player's name), to (Location name)!
We currently have (Item stock variable) (Item Name) on sale for (Addition field price) each!

Sorry if the answer for this is really easy to find, because I am having some problems finding some examples to work off of in the documentation.
User avatar
Tony Li
Posts: 22163
Joined: Thu Jul 18, 2013 1:27 pm

Re: Actor Names / Items / Locations in Dialogue Text

Post by Tony Li »

Hi,

For the player's and conversant's (NPC's) display names, you can use the [var=Actor] and [var=Conversant] markup tags. You can use [var=variable] for any other variables, too. When a conversation starts, it sets four variables:
  • Variable["Actor"]: Display name of the conversation's actor.
  • Variable["ActorIndex"]: Index in the Actor[] Lua table (e.g., "Player" in Actor["Player"]).
  • Variable["Conversant"]: Display name of the conversation's conversant.
  • Variable["ConversantIndex"]: Index in the Actor[] Lua table of the conversant (e.g., "Bob" in Actor["Bob"] if Bob is the conversant).
You can also set your own variables, of course. Example C# code:

Code: Select all

DialogueLua.SetVariable("ItemStock", 99);
DialogueLua.SetVariable("ItemName", "Red Balloons");
DialogueLua.SetVariable("FieldPrice", "1 gold");
  • Dialogue Text: "We currently have [var=ItemStock] [var=ItemName] on sale for [var=FieldPrice] each!"
For fields of other types such as actors and locations, you can use the [lua(code)] markup tag.

Example:
  • Dialogue Text: "Welcome, <b>[var=Actor]</b>m to [lua(Actor[Variable["ConversantIndex"]].ShopName)]!
You can also connect your own C# methods to Lua (see the video tutorial in the manual's Tutorials section) and use that in [lua(code)] tags. For example, if you have a C# method named GetPlayerHometown(). Example:
  • Dialogue Text: "Nice to see a visitor from [lua(GetPlayerHometown())]."


You can also manipulate the entire subtitle text before it's display if you want. To do that, add a script with an OnConversationLine method to the Dialogue Manager or one of the conversation participants. Example:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    // Replace any instances of "<weather>" with the return value of some function named GetWeather():
    subtitle.formattedText.text = subtitle.formattedText.text.Replace("<weather>", GetWeather());
}
Post Reply