Page 1 of 1

Search Localized Fields by Asset?

Posted: Fri Mar 15, 2024 8:06 am
by Luphan
Hi! After searching from this forum

I did found out that you can get localized field from actor through this:

"DialogueLua.GetLocalizedActorField(actor.Name, "VARIABLE_NAME");"

yet I was wondering if there's a way to check not just from the actor, but for all kinds of asset(locations, quest, items)?

Asset has variable name fields and I can access all of the field information

so... Is there a function that like structure below?

string DialogueLua.GetLocalizedField(Asset targetAsset, string originFieldName);

and returns with the localized field?

Re: Search Localized Fields by Asset?

Posted: Fri Mar 15, 2024 8:29 am
by Tony Li
Hi,

Here's the full API reference: DialogueLua

Also helpful; Lua in the Dialogue System
  • Actors: DialogueLua.Get/SetLocalizedActorField()
  • Locations: DialogueLua.Get/SetLocalizedLocationField()
  • Quests: DialogueLua.Get/SetLocalizedQuestField() -- also useful: QuestLog class which is a higher wrapper around quest Lua operations.
  • etc.

Re: Search Localized Fields by Asset?

Posted: Mon Mar 18, 2024 3:29 am
by Luphan
Hi Tony

first of all, thank you for the quick reply which make me feel relieved while develping project.

but I think you might misunderstand my question

which I think I did't express my question clearly enough this time.

(sorry for my poor English)

I did check the DialogueLua API and knew that there are functions like GetLocalizedActorField, GetLocalizedQuestField...etc

but to use these function, I need to make sure whether the asset is actor, item or quest...

I make myself a static function which will return the localized field if you provide asset and origin field name

like this:

public static string GetDialogueLocalizedField(Asset asset, string originFieldName)
{
var dialogueLanguage = PixelCrushers.DialogueSystem.Localization.language
var localizedKey = originFieldName + "_" + dialogueLanguage;
var search = asset.fields.Where(field => field.title == localizedKey && field.type == FieldType.Localization);

return search.Count() > 0 ? search.ToList()[0].value : string.Empty;
}

this way, I can get localized field through asset without knowing whether it is actor or item...

but I'm just wondering if dialogue system has this kind of utility?

would there be a concern to use utility like this?

Re: Search Localized Fields by Asset?

Posted: Mon Mar 18, 2024 12:01 pm
by Tony Li
Hi,

There's no concern to use that. It's totally fine.