Hello, I watched the videos on how to import functions which was helpful knowledge, but not with this specific case.
In my dialogue I'm trying to reference strings from a script such as HairColor, EyeColor and the likes that aren't housed in a function.
I feel like the persistent data template is what I should be utilizing but I'm not 100% sure on that. Any help would be much appreciated!
referencing variables not in a function
Re: referencing variables not in a function
Hi,
The recommended way is to write functions to get and set the script variable. Example:
Alternatively, you can store the values in Dialogue System variables, either as the primary location for the values, or just to copy them to Dialogue System variables when a conversation starts so you can reference them in the conversation. Example:
The recommended way is to write functions to get and set the script variable. Example:
Code: Select all
public string HairColor; // Can be "brown", "blond", "red", etc.
public string GetHairColor() { return HairColor; }
public void SetHairColor(string value) { HairColor = value; }
void Awake()
{
Lua.RegisterFunction("GetHairColor", this, SymbolExtensions.GetMethodInfo(() => GetHairColor()));
Lua.RegisterFunction("SetHairColor", this, SymbolExtensions.GetMethodInfo(() => SetHairColor(string.Empty)));
}
Code: Select all
void OnConversationStart(Transform actor) // Called when a conversation starts. Must be on participant or Dialogue Manager.
{
DialogueLua.SetVariable("HairColor", HairColor);
}
- Dialogue Text: "What pretty [var=HairColor] you have!"
Re: referencing variables not in a function
That was exactly what I was looking for. Thank you so much for your help and quick response. It's much appreciated!
Re: referencing variables not in a function
Happy to help!