How to embed external data in dialogue strings?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
njg
Posts: 14
Joined: Thu Feb 12, 2015 3:10 pm

How to embed external data in dialogue strings?

Post by njg »

Hi all,



Question from new user of Dialogue System here. Is it possible to embed external data in dialogue strings. I have an external database backing my Unity game with assorted attributes assigned to each game object and would like to be able to embed some of those attributes as text for the player to respond to, in the dialogue messages at various stages of gameplay. I have read the manual and probably misunderstood it as usual, but am curious if it is possible and if so how to do so? If the information is contained in the manual or a tutorial a pointer would be appreciated.



thanks,



Nick
User avatar
Tony Li
Posts: 21025
Joined: Thu Jul 18, 2013 1:27 pm

How to embed external data in dialogue strings?

Post by Tony Li »

Hi Nick,



Yes, you can embed external data in custom fields, or directly in the dialogue text. We've had some studios do crazy things with this, like embedding entire Lua programs in dialogue text and quest entry text. When the player completes a quest entry, it runs the Lua program, which updates things in the game world.



One of the most common approaches is to embed Lua information using markup tags. For example, you can use the [var=] tag to embed the value of a Lua variable. When the Dialogue System starts a conversation, it sets the Lua variables "Actor" and "Conversant" to the names of the participants (usually the PC and NPC). You can get the NPC to refer to the PC's name by setting the Dialogue Text field to:

Hi, [var=Actor]! How are you?

If your Lua expression is more complicated than a single variable, you can use the [lua] tag:

Greetings, [lua(RandomElement(Sir|Milord|Master))].

If you want to pull data from an external source, you can either use DialogueLua to populate the Lua environment with the data in OnConversationStart() or register your own C# methods as Lua functions.



Here's an example a studio used. During a conversation, certain additional NPCs can interject their own opinions. But the studio only want the NPCs to interject if they're close to the PC. If they've wandered off, they won't interject. The studio defined a C# function IsNearPC() and registered it with Lua. Then they used it in the Conditions field (which is a Lua condition):

Conditions: IsNearPC("Fred")

Dialogue Text: "I, Fred, have something to interject! Booya!"

The Dialogue System is quite flexible, and there are other ways to embed information, too. If the info above doesn't cover what you're after, let me know and I can make other suggestions.
njg
Posts: 14
Joined: Thu Feb 12, 2015 3:10 pm

How to embed external data in dialogue strings?

Post by njg »

Hi,



Thanks for the prompt reply, this has given me some ideas to try, I will give it another try and see how it goes.







Nick
Post Reply