Page 1 of 2

Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 6:55 am
by christianwiele
Hi,

I try to get the localized display name of my actor, but I get an exception.

This is the Dialogue Text:
Are you [lua( GetLocalizedText("Actor", "Chief", "Display Name") )]?

And this is the exception:

Dialogue System: Lua code 'return GetLocalizedText("Actor", "Chief", "Display Name")' threw exception 'Tried to invoke a function call on a non-function value. If you're calling a function, is it registered with Lua?'

I thought this Lua function is part of the standard, or do I miss a component?

Thanks, Christian

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 8:44 am
by Tony Li
Hi Christian,

It's part of the standard set of Lua functions, and I just verified that it works correctly in DS version 2.2.22. In DemoScene1, I set the Player actor's Display Name and added this text to the text of Private Hart's first line:

[lua( GetLocalizedText("Actor", "Player", "Display Name") )]

Are there any other prior errors or warnings in the Console?

If you temporarily set the Dialogue Manager's Other Settings > Debug Level to Info and reproduce the issue, does this line appear anywhere before the error?

Dialogue System: Unregistering Lua function 'GetLocalizedText'

Can you back up your project and try updating to version 2.2.22?

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 9:45 am
by christianwiele
Hi Tony,

in the demo scene, all Lua functions are registered correctly. In my scene, there are several functions missing. All functions up to the debug entry 'Dialogue System: Loaded master database '' ' are registered. They are registered through the DialogueSystemController.

Dialogue System: Registering Lua function GetEntryBool
UnityEngine.Debug:Log (object)
PixelCrushers.DialogueSystem.Lua:RegisterFunction (string,object,System.Reflection.MethodInfo) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:286)
PixelCrushers.DialogueSystem.DialogueSystemController:RegisterLuaFunctions () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/DialogueSystemController.cs:1947)
PixelCrushers.DialogueSystem.DialogueSystemController:Awake () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Manager/DialogueSystemController.cs:417)


The functions that are missing come after that and are registered differently. They are somehow registered after some UI event, which is missing in my case:

Dialogue System: Registering Lua function GetLocalizedText
UnityEngine.Debug:Log (object)
PixelCrushers.DialogueSystem.Lua:RegisterFunction (string,object,System.Reflection.MethodInfo) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:286)
PixelCrushers.DialogueSystem.DialogueLua:RegisterDialogueSystemFunctions () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/DB/DialogueLua.cs:593)
PixelCrushers.DialogueSystem.DialogueLua:RegisterLuaFunctions () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/DB/DialogueLua.cs:97)
PixelCrushers.DialogueSystem.DialogueLua/<RegisterLuaFunctionsAfterFrame>d__17:MoveNext () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/DB/DialogueLua.cs:105)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

And BTW, I am on 2.2.22

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 9:57 am
by Tony Li
When you're playing in the editor, is the Game view visible?

Several Lua functions, including GetLocalizedText, wait for the end of the first frame to register. The Unity editor has a quirk where it never triggers the "end of frame" if the Game view is not visible.

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 10:17 am
by christianwiele
Yes, the game view is visible. But it is quite a heavy scene to load.

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 10:52 am
by Tony Li
Is the conversation configured to start as soon as the scene starts, like maybe in Awake, OnEnable, or Start? And, if so, is [lua(GetLocalizedText(...))] used in the first dialogue entry? I don't know that it would be a problem; I'm just trying to gather data.

Feel free at any point to send a reproduction project to tony (at) pixelcrushers.com if you like.

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 11:22 am
by christianwiele
The conversation is started manually (using the UCC integration), and also starting a different conversation first makes no difference. It also occurs in the build, so it is no issue of the editor.

Which component triggers the registration?

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 11:48 am
by christianwiele
I think I found the issue. I have a menu / lobby scene which has no Dialogue Manager, but the DialogueLua static class is already initialized in that scene without a corresponding Lua environment. How to fix this?

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 1:19 pm
by Tony Li
That should be fine. The Lua class (as in Lua.RegisterFunction) is static, too. I'll try to set up a reproduction scenario here today.

Re: Exception with GetLocalizedText in Lua

Posted: Mon Nov 01, 2021 2:14 pm
by christianwiele
I checked that the functions are indeed registered in the lobby scene, and there are no unregistrations after that. Still, it says they are not registered when trying to access them.