Page 1 of 1

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

Posted: Mon Oct 25, 2021 11:40 am
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...)

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

Posted: Mon Oct 25, 2021 11:44 am
by etsapekis
While it would still be good to know, I think I'll just work around the issue and use the "Items" definitions

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

Posted: Mon Oct 25, 2021 11:51 am
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

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

Posted: Mon Oct 25, 2021 12:48 pm
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.

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

Posted: Mon Oct 25, 2021 2:56 pm
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

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

Posted: Mon Oct 25, 2021 3:26 pm
by Tony Li
That would be a handy feature. I'll add that in the next release.

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

Posted: Mon Oct 25, 2021 3:31 pm
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?

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

Posted: Mon Oct 25, 2021 3:46 pm
by Tony Li
No, you can do that. Add the field in the All Fields section:

customFieldTypeSceneType.png
customFieldTypeSceneType.png (51.56 KiB) Viewed 839 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.

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

Posted: Fri Oct 29, 2021 10:11 pm
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?

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

Posted: Sat Oct 30, 2021 8:21 am
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");
}