Basic Syntax Help

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
RoboticPotato
Posts: 7
Joined: Mon Jan 26, 2015 6:15 pm

Basic Syntax Help

Post by RoboticPotato »

Hi,

I'm trying to do some basic stuff, but I can't figure out the syntax. It would be great if we could have all the lua/dialog examples in one place. I've been looking at the docs and examples for hours but I can't figure out some stuff like:

For example, I have a Monster which is an actor. I added the Fields HP and AttackDmg.

I'd like to do something like

"You are fighting a [var=Conversant] It has an attack of [lua(Variable['Conversant.AttackDmg'])]."

But that code is returning a nil.
What am I missing here? How do we access fields within a variable?

Also, is there a way to dynamically assign Actors/Conversants in Code? Like I have a fight conversation- I want the same conversation to be used across multiple 'monsters' which are Actors. It would be great if I could pull the current conversation node in a sequence and change the actor values on the fly.
User avatar
Tony Li
Posts: 21046
Joined: Thu Jul 18, 2013 1:27 pm

Re: Basic Syntax Help

Post by Tony Li »

Hi,

In the next version, I'll consolidate the Lua examples and include at least one of each type.
RoboticPotato wrote:I'd like to do something like

"You are fighting a [var=Conversant] It has an attack of [lua(Variable['Conversant.AttackDmg'])]."
Try this:

"You are fighting a [var=Conversant] It has an attack of [lua( Actor[Variable['Conversant'].AttackDmg )]."

AttackDmg is a field in the Actor[] table. You're looking up the element in the actor table (i.e., the actor) whose name is stored in Variable['Conversant'].
RoboticPotato wrote:Also, is there a way to dynamically assign Actors/Conversants in Code? Like I have a fight conversation- I want the same conversation to be used across multiple 'monsters' which are Actors. It would be great if I could pull the current conversation node in a sequence and change the actor values on the fly.
Yes. I'll post an example here as soon as I can. I have to run out to attend to an emergency, but I'll be back online ASAP.
User avatar
Tony Li
Posts: 21046
Joined: Thu Jul 18, 2013 1:27 pm

Re: Basic Syntax Help

Post by Tony Li »

Hi,

I'm not sure at which point you want to dynamically assign Actors and Conversants, so I'll post two examples.

Example 1: Assign at conversation start

This is like the generic shopkeeper example that you may have run across in the manual.
Let's say you have three monster actors: a generic Monster, and a Troll and Goblin. And you have two players, Gimli and Legolas.

You can specify any two characters as the primary participants (Conversation Actor/Conversant) when starting a conversation. They don't have to be the actors assigned to that conversation in the database. The Dialogue System will swap them on the fly.

So let's say you have a conversation "Battle Start" like this:
  • Conversation Actor: Player
  • Conversation Conversant: Monster
  • START
    • Monster: "You are fighting a [var=Conversant]. It has an attack of [lua( Actor[Variable['Conversant']].AttackDmg )]."
      • Monster: "It growls, 'Prepare to die, [var=Actor]!'"
If you start the conversation in code, you can use either of these or others:

Code: Select all

DialogueManager.StartConversation("Battle Start", Legolas.transform, Goblin.transform);
or:

Code: Select all

DialogueManager.StartConversation("Battle Start", Gimli.transform, Troll.transform);
If you omit either transform, it will look for a GameObject matching the name of the participant assigned in the conversation. If you involve extra characters in the conversation (beyond the primary Conversation Actor/Conversant), the extra character in the conversation needs to match a GameObject in the scene. The GameObject can either match the actor's name in the database, or it can have an Override Actor Name to match up the GameObject with an actor in the database.

Here's an example scene: GenericMonsterConversation_2016-12-23.unitypackage

The example scene uses Conversation Triggers to which I've assigned characters manually in the inspector.


Example 2: Change participants mid-conversation

If you want to set the Lua variables Variable["Actor"] and Variable["Conversant"], you can set them manually using DialogueLua.SetVariable() or use DialogueLua.SetParticipants():

Code: Select all

DialogueLua.SetParticipants("Gimli", "Goblin"); 
If you want to associate a different GameObject, change DialogueManager.ConversationModel.ActorInfo and ConversantInfo (both of which are CharacterInfo properties):

Code: Select all

DialogueManager.ConversationModel.ActorInfo.transform = Gimli.transform;
DialogueManager.ConversationModel.ConversantInfo.transform = Goblin.transform; 
RoboticPotato
Posts: 7
Joined: Mon Jan 26, 2015 6:15 pm

Re: Basic Syntax Help

Post by RoboticPotato »

Thanks! That was exactly what I was looking for.
User avatar
Tony Li
Posts: 21046
Joined: Thu Jul 18, 2013 1:27 pm

Re: Basic Syntax Help

Post by Tony Li »

Happy to help!
Post Reply