Get Random Actor's property as var

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
bbjones
Posts: 21
Joined: Mon Aug 17, 2020 11:56 am

Get Random Actor's property as var

Post by bbjones »

Example.
Conversation nodes use generic actors, at run-time the actor/conversant are set via StartDialogue() or trigger etc.

Conversant:
Name = Fred Jackson
Display name = Freddy J.
Age = 22 (this is a custom field on the Actor template)

In conversation node I can access Fred's name using:
"And how are we feeling today, [var=Conversant]?"

That will display either the actor name or display name depending on if UseDisplayName is checked.
But what about other properties from the Conversant and more importantly custom template fields?

I get that I can access actor fields via the table index, eg. Actor["Fred_Jackson"].Age = 22

But in the conversation above I don't know the player index as it could be any actor set at runtime.

I'm expecting to be able to access properties in this way, but it doesn't work (nil is the value returned).
"And how are we feeling today, [var=Conversant.Age]?"

Also, is it possible to debug and step through Lua code?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get Random Actor's property as var

Post by Tony Li »

Hi,

When a conversation starts, the Dialogue System will set two conversant-related variables:
  • Variable["Conversant"]: The Display Name (e.g., "Freddy J.")
  • Variable["ConversantIndex"]: The Actor[] table index (e.g., "Fred_Jackson")
To show the Age field, use the [lua(code)] tag:

"I'm feeling pretty rough for only [lua( Actor[Variable["ConversantIndex"]].Age )] years old."

The Lua engine is written in native C#, so you can step through it. More helpful, though, may be to set the Dialogue Manager's Other Settings > Debug Level to Info. This will log a lot of Lua activity to the Console window, which may provide enough info for your debugging needs.
bbjones
Posts: 21
Joined: Mon Aug 17, 2020 11:56 am

Re: Get Random Actor's property as var

Post by bbjones »

Works perfectly, thanks!

I was mostly looking for a way to store a variety of name options for a random character in the conversation, eg:

Full_Name: Fred Jackson
Informal_Name: Freddy
Formal_Name: Mr. Jackson
etc

That code does the trick.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get Random Actor's property as var

Post by Tony Li »

Great! Glad to help.
Post Reply