I want to have an NPC that yells in a different language when he's upset. the language will change based on the player's system language.
Your solution definitely fits my use-case, but I changed it to get the localized text from the localized field in the template.
Here was my solution:
Code: Select all
public StringReference nativeLanguageCode;
public StringReference targetLanguageCode;
public void CheckChangeLanguageToNativeForOneEntry(Subtitle subtitle) {
if (Field.LookupBool(subtitle.dialogueEntry.fields, "useNativeLanguage")) {
var nativeString = Field.LookupValue(subtitle.dialogueEntry.fields, nativeLanguageCode.Value);
subtitle.formattedText.text = nativeString;
}
}
public void CheckChangeLanguageToNativeForOneEntry(Response[] responses) {
foreach (var response in responses) {
if (Field.LookupBool(response.destinationEntry.fields, "useNativeLanguage")) {
var nativeString = Field.LookupValue(response.destinationEntry.fields, nativeLanguageCode.Value);
response.formattedText.text = nativeString;
}
}
}
I had a little bit of confusion over the naming of Response.destinationEntry. It mentions that, "The dialogue entry that this response links to. In other words, if this response is selected, the dialogue system will go to this dialogue entry."
This led me to believe that the destinationEntry is a reference to the DialogueEntry that shows after the response is interacted with. However, it seems like what's actually happening is that Response.destinationEntry.fields shows a representation of the List<Field> of the Response itself instead of the one referenced down the line.
Is that correct? This is just for my understanding.
Additionally, I have another question regarding Text Tables. is there any way we can get the Field ID of a Field Text value by using the Field Text value itself? I'm trying to get a value in a different language without knowing the Field name or the Field ID.