This question might have been answered before, but I couldn't find anything related.
I wish to be able to change the value of a variable inside of a script of mine depending on the responses the player gives.
A simple example:
Q: Are you a boy or a girl?
R: Boy.
then inside a "character_attributes" script change the gender to a "boy" string, or a "boy" bool to "true" etc...
What should I learn or study to do that with dialogue system?
Thanks in advanced!
How can I edit the value of a costum script variable with dialogue sequences.
Re: How can I edit the value of a costum script variable with dialogue sequences.
Hi,
Add methods to your script to get and set the gender variable. For example:
Then make these methods available to the Dialogue System's Lua environment by registering them as Lua functions. Grabbing some of the code from Templates / Scripts / TemplateCustomLua.cs, you could expand the script like this:
Then you can use GetGender() and SetGender() in your conversations' Conditions and Script fields.
Add methods to your script to get and set the gender variable. For example:
Code: Select all
public class PlayerGender : MonoBehaviour
{
public string gender = "unspecified";
public void SetGender(string value) { gender = value; }
public string GetGender() { return gender; }
}
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class PlayerGender : MonoBehaviour
{
public string gender = "unspecified";
void OnEnable()
{
Lua.RegisterFunction("SetGender", this, SymbolExtensions.GetMethodInfo(() => SetGender(string.Empty)));
Lua.RegisterFunction("GetGender", this, SymbolExtensions.GetMethodInfo(() => GetGender()));
}
void OnDisable()
{
Lua.UnregisterFunction("SetGender");
Lua.UnregisterFunction("GetGender");
}
public void SetGender(string value) { gender = value; }
public string GetGender() { return gender; }
}
Re: How can I edit the value of a costum script variable with dialogue sequences.
Thanks Toni!
I'll study it and see what I can do.
As always thanks for your time!
I'll study it and see what I can do.
As always thanks for your time!
Re: How can I edit the value of a costum script variable with dialogue sequences.
Glad to help! If you have any questions about it, just let me know.