Page 1 of 1
How can I edit the value of a costum script variable with dialogue sequences.
Posted: Sat Sep 21, 2019 12:43 pm
by gdbaradit
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!
Re: How can I edit the value of a costum script variable with dialogue sequences.
Posted: Sat Sep 21, 2019 1:22 pm
by Tony Li
Hi,
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; }
}
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:
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; }
}
Then you can use GetGender() and SetGender() in your conversations'
Conditions and
Script fields.
Re: How can I edit the value of a costum script variable with dialogue sequences.
Posted: Fri Sep 27, 2019 11:24 am
by gdbaradit
Thanks Toni!
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.
Posted: Fri Sep 27, 2019 1:12 pm
by Tony Li
Glad to help! If you have any questions about it, just let me know.