How to access to variables ?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jghesquiere
Posts: 10
Joined: Thu Aug 04, 2016 10:58 am

How to access to variables ?

Post by jghesquiere »

Hello,

I'm new to Dialogue System. I use Articy:Draft and I use templates.

I want to know how to access to the global variables in the SequencerCommand templates scripts.

The only thing I found is, for exemple : PixelCrushers.DialogueSystem.DialogueLua.GetVariable("Test");

I want to access to the global variables and to the actors variables.

Can you explain me how to do it ?

Thank you very much !

:)
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to access to variables ?

Post by Tony Li »

Hi,

Thanks for using the Dialogue System!

You're almost there.

For convenience, at the top of your sequencer command script, add:

Code: Select all

using PixelCrushers.DialogueSystem; 
You can determine variable names by looking on the Dialogue Editor window's Variables tab. When converted from articy, they have the format variablegroup.variablename. The Dialogue System uses Lua internally. Lua is a dynamically-typed language, which means a variable can store any data type (Number, Text, Boolean, etc.). When you get the variable value in a C# or UnityScript script, you should specify the type at the end of DialogueLua.GetVariable(). For example:

Code: Select all

int score = DialogueLua.GetVariable("MyGlobals.Score").AsInt;
bool isAlive = DialogueLua.GetVariable("MyGlobals.Alive").AsBool;
float cost = DialogueLua.GetVariable("CurrencyVariables.DollarCost").AsFloat;
string secretPhrase = DialogueLua.GetVariable("Secrets.TheSecretPhrase").AsString;
To get the value of an actor field, use DialogueLua.GetActorField():

Code: Select all

int age = DialogueLua.GetActorField("Player", "Age").AsInt;
If you have any other questions about this, just let me know!
jghesquiere
Posts: 10
Joined: Thu Aug 04, 2016 10:58 am

Re: How to access to variables ?

Post by jghesquiere »

Awesome, thank you !!
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to access to variables ?

Post by Tony Li »

Happy to help! If you have any questions about those function calls, just let me know.
jghesquiere
Posts: 10
Joined: Thu Aug 04, 2016 10:58 am

Re: How to access to variables ?

Post by jghesquiere »

Hello,

I have a new question about the SequencerCommand.
As you know I use Articy:Draft with Dialogue System.
In Articy, I have made a HUB with a custom template :

Image

- Sequence : LoadScene();
- Scene : DropDown with strings

And in Dialogue System : SequencerCommandLoadScene.cs

I don't want to have to type in the Sequence field : LoadScene("MainMenu"); or LoadScene("Salle5"); etc...
I want to just set the good field of the dropdown list.

Currently I have this :

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
using UnityEngine.SceneManagement;

namespace PixelCrushers.DialogueSystem.SequencerCommands {

	public class SequencerCommandLoadScene: SequencerCommand {
		public void Start() {
			SceneManager.LoadScene(GetParameter(0));
			Stop();
		}
	}
}
But I want to get the parameter "Scene" from the current HUB template.

Is it possible ?

Thank you.
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to access to variables ?

Post by Tony Li »

Yes, you should be able to modify it as shown below. I'm out of the office, so I'm not able to test it. There might be typos.

In the articy Converter window, make sure that you're importing dropdowns as strings, not ints. I believe the dropdown defaults to int.

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
using UnityEngine.SceneManagement;

namespace PixelCrushers.DialogueSystem.SequencerCommands {

    public class SequencerCommandLoadScene: SequencerCommand {
        public void Start() {
            var currentEntry = DialogueManager.CurrentConversationState.subtitle.dialogueEntry;
            var dropdownValue = Field.LookupValue(currentEntry.fields, "Scene");
            SceneManager.LoadScene(dropdownValue);
            Stop();
        }
    }
}
jghesquiere
Posts: 10
Joined: Thu Aug 04, 2016 10:58 am

Re: How to access to variables ?

Post by jghesquiere »

OK thank you. It works very well.
User avatar
Tony Li
Posts: 22145
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to access to variables ?

Post by Tony Li »

Glad I could help!
Post Reply