Page 1 of 1

Get Random Actor's property as var

Posted: Wed Aug 26, 2020 4:02 pm
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?

Re: Get Random Actor's property as var

Posted: Wed Aug 26, 2020 5:02 pm
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.

Re: Get Random Actor's property as var

Posted: Wed Aug 26, 2020 7:04 pm
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.

Re: Get Random Actor's property as var

Posted: Wed Aug 26, 2020 8:38 pm
by Tony Li
Great! Glad to help.