Scripting with Dialogue System Variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
annathehank
Posts: 95
Joined: Sun May 03, 2020 2:17 pm

Scripting with Dialogue System Variables

Post by annathehank »

Hello <3

I just had a few clarification questions for using the Dialogue System classes/namespaces in scripting.

1) Do I need to/can I include something in the 'using' area of a script? Such as Using PixelCrushers.DialogueSystem.
2) When referring to a variable set up in the Dialogue Manager in a C# script, what's the best practice? Is it PixelCrushers.DialogueSystem.DialogueLua.GetVariable("variable"), and would I still need all of that if the pixelcrushers.dialguesystem is in the using scetion? Or could I just use DialogueLua.GetVariable("name")?
3) Do we need to clarify .asString or .asInt for each variable? What if it's a bool?
4) Are the actors listed in the manager a class? And can we call upon the class in scripts? Is there a way to assign a variable to an actor?

The process I'm trying to set up is an image appearing when certain variables are met.
I'm trying to, basically, build something like this:

Code: Select all

public GameObject alertnotif;
int RelLvl;
int TalkLvl;

void Start()
{
//Not sure how to grab the class/list of actors
var NPC = (whatever I would put to grab the list of actors)
 //not sure how to get the variable to relate to specific actors either
foreach (Actor in NPC)
  {RelLvl = PixelCrushers.DialogueSystem.DialogueLua.GetVariable("npcnameRelLvl").asInt;
   TalkLvl = PixelCrushers.DialogueSystem.DialogueLua.GetVariable("npcnameTalkLvl").asInt;
   if(TalkLvl * 10 + 1 > RelLvl) 
     {alertnotif.SetActive(true);}
   }
}

Sorry for the long list of questions, hopefully they make sense and aren't super complicated to answer <3 Thank you for your time and help again!
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scripting with Dialogue System Variables

Post by Tony Li »

Hi,

Put this at the top of your script:

Code: Select all

using PixelCrushers;
using PixelCrushers.DialogueSystem;
The first line may not be necessary; it's useful if you're making calls to the SaveSystem class.

Then you can omit PixelCrushers.DialogueSystem from DialogueLua.GetVariable. In Lua, a variable can be any type. To get the variable's value as a specific type in your C# script, you can use .asBool, .asString, .asInt, or .asFloat.

In addition to variables, which you can get using DialogueLua.GetVariable, you can also get and set actor fields. For example, to change the Player actor's Display Name, you could use this C# code:

Code: Select all

DialogueLua.SetActorField("Player", "Display Name", "Anna");
Or, to get the Player's Health points as an int (assuming you've defined such a field in your database):

Code: Select all

int health = DialogueLua.GetActorField("Player", "Health").asInt;
annathehank
Posts: 95
Joined: Sun May 03, 2020 2:17 pm

Re: Scripting with Dialogue System Variables

Post by annathehank »

Thank you for pointing out the actor fields, too! I can use them instead of variables for the relationship levels and points.

I think I may have figured out how to make the scripting for everything work...*hopefully* :lol:
I'll keep you updated (a.k.a. probably be back tomorrow when it doesn't work)
annathehank
Posts: 95
Joined: Sun May 03, 2020 2:17 pm

Re: Scripting with Dialogue System Variables

Post by annathehank »

I actually do have just a quick follow up with this:

Is there a way to populate Actor fields in quest states/conversations in a similar manner to using [var=name]?

I've tried a few different ways but can't seem to figure it out

My gut instinct was to just put this:
Actor["name"].fieldname
but I think that's just for assigning/checking not displaying values.
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Scripting with Dialogue System Variables

Post by Tony Li »

Hi,

Variables have the shortcut [var=variable] markup tag.

For other data, you'll need to use the [lua(code)] markup tag, such as:
  • Dialogue Text: "I'd never guess you're [lua(Actor["Player"].Age)]! You look so young!"
annathehank
Posts: 95
Joined: Sun May 03, 2020 2:17 pm

Re: Scripting with Dialogue System Variables

Post by annathehank »

Ahh thank you so much!! <3
I kept trying different versions of () and [] to get it to work :lol:
Post Reply