Page 1 of 1

How to write "Found"/"Not Found" in quest description from a variable

Posted: Wed Feb 09, 2022 9:42 pm
by Strook
Hello! This should be pretty straightforward, but I feel like Im missing something:

- I have some boolean variables related to the state of some objects in game
- I have a quest showing the state of those objects, and I'd like to display it like this :

-Object A: Found
-Object B: Not Found
-Object C: Found
Right now I have (as a placeholder) simply written it like this in my Quest Entry Description field:

Code: Select all

-Object A: [var=QuestObjects.ObjectA]
Where Object A is my boolean. Of course this displays "- Object A: true" which is not what I want!


What would be the easiest way to achieve something like this?

Thanks :)

Re: How to write "Found"/"Not Found" in quest description from a variable

Posted: Thu Feb 10, 2022 8:46 am
by Tony Li
Hi,

You'll need to use a Lua expression. In case you want to dig into the details of how it works, see Ternary Operator. If you just want to get it working, change this:

- Object A: [var=QuestObjects.ObjectA]

to this:

- Object A: [lua( Variable["QuestObjects.ObjectA"] and "Found" or "Not Found" )]

Re: How to write "Found"/"Not Found" in quest description from a variable

Posted: Thu Feb 10, 2022 7:47 pm
by Strook
Awesome, Thanks a lot Tony

Re: How to write "Found"/"Not Found" in quest description from a variable

Posted: Thu Feb 10, 2022 8:37 pm
by Tony Li
Happy to help!

Re: How to write "Found"/"Not Found" in quest description from a variable

Posted: Thu Feb 17, 2022 7:53 pm
by Strook
i was just wondering, how would you go about localizing this? Is it possible to grab the keyword from a text table? Thanks!

Re: How to write "Found"/"Not Found" in quest description from a variable

Posted: Thu Feb 17, 2022 10:11 pm
by Tony Li
You could put the localization straight into the localization fields:
  • Dialogue Text: Object A: [lua( Variable["QuestObjects.ObjectA"] and "Found" or "Not Found" )]
  • es: Object A: [lua( Variable["QuestObjects.ObjectA"] and "Detectado" or "No detectado" )]
  • fr: Object A: [lua( Variable["QuestObjects.ObjectA"] and "Détecté" or "Non-détecté" )]
  • ja: Object A: [lua( Variable["QuestObjects.ObjectA"] and "位置した" or "見つかりません" )]

Or you could register DialogueManager.GetLocalizedText() with Lua. Call it something like GetTranslation() because GetLocalizedText() is already a Lua function that gets the localized version of database content.

Code: Select all

Lua.RegisterFunction("GetTranslation", null, SymbolExtensions.GetMethodInfo(() => DialogueManager.GetLocalizedText(string.Empty)));
Then use that C# method:
  • Object A: [lua( Variable["QuestObjects.ObjectA"] and GetTranslation("Found") or GetTranslation("Not Found") )]