Search Localized Fields by Asset?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Luphan
Posts: 13
Joined: Wed Jun 07, 2023 5:39 am

Search Localized Fields by Asset?

Post 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?
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Search Localized Fields by Asset?

Post 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.
Luphan
Posts: 13
Joined: Wed Jun 07, 2023 5:39 am

Re: Search Localized Fields by Asset?

Post 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?
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Search Localized Fields by Asset?

Post by Tony Li »

Hi,

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