Accessing values of variables from Dialogue Databases that are instantiated at runtime
-
- Posts: 22
- Joined: Wed Aug 19, 2020 2:44 pm
Re: Accessing values of variables from Dialogue Databases that are instantiated at runtime
Okay, that is super-helpful. Will use it this way.
-
- Posts: 22
- Joined: Wed Aug 19, 2020 2:44 pm
Re: Accessing values of variables from Dialogue Databases that are instantiated at runtime
Code: Select all
string luaScript = @"Actor['{ActorName}'] = \{ Name = '{ActorName}', Display_Name = '{ActorDisplayName}'\}";
Lua.Run(luaScript);
dialogueActor = gameObject.AddComponent<DialogueActor>();
dialogueActor.actor = ActorName;
If I replace the $sign with the @ as shown in the above snippet, which at least allows me to get into playmode, I get a syntax error, indicating that the string has not been parsed successfully.
If I remove the @ and / entirely, I get a stack overflow error.
As someone unfamiliar with Lua(both Lua itself and the Dialogue System's Lua class), I am not entirely sure about how it parses a C# string, especially since the C# 6.0 version of string interpolation no longer works.
Apologies if it seems like I am asking for spoonfeeding.
Re: Accessing values of variables from Dialogue Databases that are instantiated at runtime
Hi,
String interpolation of the form $"...{variable}..." is only available in newer versions of Unity that are using the C# 6.0 standard or higher. Try String.Format() or regular string concatenation:
String interpolation of the form $"...{variable}..." is only available in newer versions of Unity that are using the C# 6.0 standard or higher. Try String.Format() or regular string concatenation:
Code: Select all
string luaScript = "Actor['" + ActorName + "'] = { Name = '" + ActorName + "', Display_Name = '" + ActorDisplayName + "'}";
Lua.Run(luaScript);
-
- Posts: 22
- Joined: Wed Aug 19, 2020 2:44 pm
Re: Accessing values of variables from Dialogue Databases that are instantiated at runtime
Hello,
That worked for me! I really appreciate all the help.
That worked for me! I really appreciate all the help.
-
- Posts: 22
- Joined: Wed Aug 19, 2020 2:44 pm
Re: [SOLVED]Accessing values of variables from Dialogue Databases that are instantiated at runtime
I may have spoken too soon, I see that I am getting a stack overflow error.
Where 'Bob' is derived from a parameter called ActorName and 'BobTheCapsule' is derived from a parameter called ActorDisplayName. For testing purposes I had put these as serialized variables.
Lol I end up returning to this thread again and again, thinking that I have it solved, only to see that it is not the case. The weirdest thing is that I could have sworn that BobTheCapsule was working when I implemented the solution on Friday.
Code: Select all
Lua code 'Actor['Bob'] = { Name = 'Bob', Display_Name = 'BobTheCapsule'}' threw exception 'The requested operation caused a stack overflow.'
Lol I end up returning to this thread again and again, thinking that I have it solved, only to see that it is not the case. The weirdest thing is that I could have sworn that BobTheCapsule was working when I implemented the solution on Friday.
Re: Accessing values of variables from Dialogue Databases that are instantiated at runtime
Something else is going on. That line by itself runs fine in Lua.
Can you post the C# code that you're using to run that?
Can you post the C# code that you're using to run that?
-
- Posts: 22
- Joined: Wed Aug 19, 2020 2:44 pm
Re: Accessing values of variables from Dialogue Databases that are instantiated at runtime
Sure, I am posting it below.
Tested it with both ActorDisplayName and gameObject.name(latter used only because of saving the gameObject as the same name as what we want to display on screen)
Code: Select all
public string ActorName;
//public string ActorDisplayName;
private DialogueActor dialogueActor;
void Awake()
{
string luaScript = "Actor['" + ActorName + "'] = { Name = '" + ActorName + "', Display_Name = '" + gameObject.name + "'}";
Lua.Run(luaScript);
dialogueActor = gameObject.AddComponent<DialogueActor>();
dialogueActor.actor = ActorName;
}
Re: Accessing values of variables from Dialogue Databases that are instantiated at runtime
If this happens in the same scene that the Dialogue Manager first initializes itself in, change your Awake method to Start. This will allow the Dialogue Manager to initialize itself first.
I tested this script, and it works:
If that doesn't help, please feel free to send a reproduction project to tony (at) pixelcrushers.com.
I tested this script, and it works:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class CreateRuntimeActor : MonoBehaviour
{
public string ActorName;
private void Start()
{
string luaScript = "Actor['" + ActorName + "'] = { Name = '" + ActorName + "', Display_Name = '" + gameObject.name + "'}";
Lua.Run(luaScript);
}
}
-
- Posts: 22
- Joined: Wed Aug 19, 2020 2:44 pm
Re: Accessing values of variables from Dialogue Databases that are instantiated at runtime
Okay, I shall try putting it in Start. I was testing it out in a SampleScene so the DialogueManager does initialize in this scene as well for this particular context.