How to add an enum type to possible actor's field variables?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

How to add an enum type to possible actor's field variables?

Post by etsapekis »

I would like to add a field to actors to denote their emotional state and I would prefer this to be a code defined enum instead of a text field to be safe. How can I make my enum an option in the field type (ie: among Actor, Boolean, Files, Item, etc...)
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

Re: How to add an enum type to possible actor's field variables?

Post by etsapekis »

While it would still be good to know, I think I'll just work around the issue and use the "Items" definitions
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

Re: How to add an enum type to possible actor's field variables?

Post by etsapekis »

Hmm that is still a problem because in the Dialogue Entry's Script area, setting the actor's item field that I called "Emotion" can only be done via string, so that puts me back to square one
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add an enum type to possible actor's field variables?

Post by Tony Li »

Hi,

Define a custom field type to store the value as a string in the back-end but use an enum on the front-end so the designer can only set it to valid enum values.
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

Re: How to add an enum type to possible actor's field variables?

Post by etsapekis »

I did it and the enum dropdown works in the "All Fields" section, but not in the "Script section. This appears to be a Lua wizard problem
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add an enum type to possible actor's field variables?

Post by Tony Li »

That would be a handy feature. I'll add that in the next release.
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

Re: How to add an enum type to possible actor's field variables?

Post by etsapekis »

To confirm, there's no way at the moment for a designer in a dialogue entry to select an enum value from a dropdown that I can read in code?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add an enum type to possible actor's field variables?

Post by Tony Li »

No, you can do that. Add the field in the All Fields section:

customFieldTypeSceneType.png
customFieldTypeSceneType.png (51.56 KiB) Viewed 835 times

Alternatively, add the field to the dialogue entry's template on the Templates page, and tick the Main checkbox. It will appear in the dialogue entry's main inspector section so you don't have to expand All Fields.

The only thing you can't do right now is use a custom dropdown drawer in the Lua wizards.
etsapekis
Posts: 39
Joined: Tue Oct 12, 2021 4:21 pm

Re: How to add an enum type to possible actor's field variables?

Post by etsapekis »

I know how to access actor fields via code, but not how to access the entry's "all fields" section. I seem unable to get the current entry, even. How can I get the fields for the current dialogue entry via code?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to add an enum type to possible actor's field variables?

Post by Tony Li »

Hi,

The current dialogue entry is DialogueManager.currentConversationState.subtitle.dialogueEntry.

Code: Select all

if (DialogueManager.isConversationActive)
{
    DialogueEntry entry = DialogueManager.currentConversationState.subtitle.dialogueEntry;
    string someValue = Field.LookupValue(entry.fields, "Some Field");
}

If you're inside an OnConversationLine method, you have direct access to the Subtitle:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    DialogueEntry entry = subtitle.dialogueEntry;
    string someValue = Field.LookupValue(entry.fields, "Some Field");
}
Post Reply