How to get the Actor by its index number?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Deadlybrunch
Posts: 6
Joined: Mon Jul 06, 2020 11:15 am

How to get the Actor by its index number?

Post by Deadlybrunch »

Hi, i've got a problem, please help me.
For example, I have a few Actors like below:
Actor1: "aa"
Actor2: "bb"
Actor3: "cc"
Actor4: "dd"
Actor5: "ee"
And now, i want to get the 5th Actor's name by Lua(i dont know what the 5th Actor's name is, and i only know that the Actor's index number is 5), how can i write the Lua code?
And, another question. If i want to change the 5th Actor's name from "ee" to "ff", can i use Lua to do that?If i can, how?
Thank you!
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get the Actor by its index number?

Post by Tony Li »

Hi,

You can identify an actor 3 ways:

1. By its Name field. (C# or Lua) In C# and Lua, you can get an actor by Name. You can also change the actor's "Display Name" field at runtime to change the name that's shown to the player. The Extras page has a "Discover Name" example scene that demonstrates this.

2. By its internal ID number. (C# scripting only; not Lua) If you inspect an actor, the inspector will show the actor's ID number as well as its Name, Display Name, etc. To get an actor by ID in C#, use DialogueManager.masterDatabase.GetActor(ID).

3. By its index in the dialogue database. (C# scripting only; not Lua) To get an actor by its index (the order it appears in the Dialogue Editor's Actors section), use DialogueManager.masterDatabase.actors[index]. Note that if you load more than one database at runtime (e.g., using an Extra Databases component), the indices won't necessarily be correct since the extra database(s) will be added to the end of the in-memory list.,
Deadlybrunch
Posts: 6
Joined: Mon Jul 06, 2020 11:15 am

Re: How to get the Actor by its index number?

Post by Deadlybrunch »

Thanks a lot, that will be help. I've mistaken the actor's "Display Name" with the actor's "Name", now i know that i can get the actor by its "Name", and i can change its "Display Name" to show different charactor.
Thank you!
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get the Actor by its index number?

Post by Tony Li »

Happy to help!
Post Reply