Error trying to use Display_Name

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
splinedrew
Posts: 13
Joined: Tue Mar 15, 2022 8:53 pm

Error trying to use Display_Name

Post by splinedrew »

Hello there,

I am trying to Display a players Display Name instead of manually typing it but keep getting blocked by an error.

This is the dialogue text:
How is [lua(Actor["NPC - Kaya P1"].Display_Name)] doing?

This is the setup of the character in the Actors list:
Error.JPG
Error.JPG (29.85 KiB) Viewed 382 times
But when the game runs I get the error:
Dialogue System: Lua code 'return Actor["NPC - Kaya P1"].Display_Name' threw exception 'Lookup of field 'Display_Name' in the table element failed because the table element itself isn't in the table.'
UnityEngine.Debug:LogError (object)
PixelCrushers.DialogueSystem.Lua:RunRaw (string,bool,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:228)
PixelCrushers.DialogueSystem.Lua:Run (string,bool,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:129)
PixelCrushers.DialogueSystem.Lua:Run (string,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:139)
PixelCrushers.DialogueSystem.FormattedText/<>c:<ReplaceLuaTags>b__58_0 (System.Text.RegularExpressions.Match) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Text/FormattedText.cs:263)
System.Text.RegularExpressions.Regex:Replace (string,System.Text.RegularExpressions.MatchEvaluator)
PixelCrushers.DialogueSystem.FormattedText:ReplaceLuaTags (string&) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Text/FormattedText.cs:257)
PixelCrushers.DialogueSystem.FormattedText:Parse (string,PixelCrushers.DialogueSystem.EmphasisSetting[]) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Text/FormattedText.cs:181)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinksAtPriority (PixelCrushers.DialogueSystem.ConditionPriority,PixelCrushers.DialogueSystem.DialogueEntry,System.Collections.Generic.List`1<PixelCrushers.DialogueSystem.Response>,System.Collections.Generic.List`1<PixelCrushers.DialogueSystem.Response>,System.Collections.Generic.List`1<PixelCrushers.DialogueSystem.DialogueEntry>,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:439)
PixelCrushers.DialogueSystem.ConversationModel:EvaluateLinks (PixelCrushers.DialogueSystem.DialogueEntry,System.Collections.Generic.List`1<PixelCrushers.DialogueSystem.Response>,System.Collections.Generic.List`1<PixelCrushers.DialogueSystem.Response>,System.Collections.Generic.List`1<PixelCrushers.DialogueSystem.DialogueEntry>,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:365)
PixelCrushers.DialogueSystem.ConversationModel:GetState (PixelCrushers.DialogueSystem.DialogueEntry,bool,bool,bool) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:259)
PixelCrushers.DialogueSystem.ConversationModel:GetState (PixelCrushers.DialogueSystem.DialogueEntry) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/Model/ConversationModel.cs:304)
PixelCrushers.DialogueSystem.ConversationController:OnFinishedSubtitle (object,System.EventArgs) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Controller/ConversationController.cs:270)
PixelCrushers.DialogueSystem.ConversationView:FinishSubtitle () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:418)
PixelCrushers.DialogueSystem.ConversationView:OnFinishedSubtitle () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/View/View/ConversationView.cs:425)
PixelCrushers.DialogueSystem.Sequencer:FinishSequence () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:597)
PixelCrushers.DialogueSystem.Sequencer:Update () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Sequencer/Sequencer.cs:589)
Any ideas?
User avatar
Tony Li
Posts: 22116
Joined: Thu Jul 18, 2013 1:27 pm

Re: Error trying to use Display_Name

Post by Tony Li »

Hi,

When an actor's name appears in the [] parts of the Lua Actor[] table, the name follows the rules here: Table Indices. It replaces characters such as " " (space) and "-" with underscores ("_").

Try this:

How is [lua(Actor["NPC___Kaya_P1"].Display_Name)] doing?


Side note: For the conversation's primary actor and conversant, instead of the more-complex [lua()] tag above, you can simply use [var=Actor] and [var=Conversant].
splinedrew
Posts: 13
Joined: Tue Mar 15, 2022 8:53 pm

Re: Error trying to use Display_Name

Post by splinedrew »

Thanks for the quick reply! I am using those quick tags for Actor and Conversant already, but sometimes they reference other NPCs in the game. That did the trick for me.

If I wanted to use something that was in a TextTable is there a Lua function or some documentation for that?
User avatar
Tony Li
Posts: 22116
Joined: Thu Jul 18, 2013 1:27 pm

Re: Error trying to use Display_Name

Post by Tony Li »

Hi,

In version 2.2.40, there will be a new Lua function named GetTextTableValue("key").

In the meantime, you get can it from the C# method DialogueManager.GetLocalizedText("key").

Note: The current Lua function GetLocalizedText("table", "element", "field") predates text tables. Despite the confusing name, it gets the localized version of a field in an Actor[], Item[], Quest[], or Location[] Lua table.
splinedrew
Posts: 13
Joined: Tue Mar 15, 2022 8:53 pm

Re: Error trying to use Display_Name

Post by splinedrew »

Ok sounds great, I'll try that out when the update is available. Thanks!
User avatar
Tony Li
Posts: 22116
Joined: Thu Jul 18, 2013 1:27 pm

Re: Error trying to use Display_Name

Post by Tony Li »

Here's a patch if you'd like early access to that function:

DS_GetTextTableValuePatch_2023-08-30.unitypackage
Post Reply