Get Script values before hand using Playmaker

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Alatriste
Posts: 181
Joined: Wed Nov 11, 2015 5:07 pm
Contact:

Get Script values before hand using Playmaker

Post by Alatriste »

Hi,

Is there a way to get the values of the variables I added in the script field of an answer using the Playmaker extension?
For instance, if I hover with the mouse over one of the answers, I'd like to show the consequences of that answer, which are contained in the script field.

I've no clue about how to do that. :?
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get Script values before hand using Playmaker

Post by Tony Li »

Hi,

A small script (below) will make it a lot easier. Here's an example project that also includes the script:

PlayMakerDialogueHints_2016-10-31.unitypackage

It assumes you've imported PlayMaker's UGUI Proxy package.

In the example, the response nodes have a custom field named "Hint". The script, which is added to the Response Button, has a method SetHintVariable that copies the Hint into a Dialogue System variable (also named "Hint"). The Response Button handles the OnPointerEnter event by calling SetHintVariable and then sending an event to a PlayMaker FSM on the Response Panel.

The PlayMaker FSM looks up the Dialogue System variable and sets the HintText UI element.

The script also has alternative method SetHintVariableToScript that you can use instead of SetHintVariable if you actually want to show the content of the Script field. But since the Script field is raw Lua code, I figure you'll probably want to use a dedicated Hint field so you can make it look exactly the way you want.

The Response Button also handles the OnPointerExit event by clearing the hint.

ResponseHintToVariable.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class ResponseHintToVariable : MonoBehaviour
{

    public string hintField = "Hint";

    public void SetHintVariable()
    {
        var response = GetComponent<UnityUIResponseButton>().response;
        var hint = Field.LookupValue(response.destinationEntry.fields, hintField);
        DialogueLua.SetVariable("Hint", hint);
    }

    public void ClearHintVariable()
    {
        DialogueLua.SetVariable("Hint", string.Empty);
    }

    public void SetHintVariableToScript()
    {
        var response = GetComponent<UnityUIResponseButton>().response;
        DialogueLua.SetVariable("Hint", response.destinationEntry.userScript);
    }
} 
User avatar
Alatriste
Posts: 181
Joined: Wed Nov 11, 2015 5:07 pm
Contact:

Re: Get Script values before hand using Playmaker

Post by Alatriste »

Wow! Thanks a lot Tony! I never used EventsTriggers but I think I understood what you said following the example. It seems pretty straight forward so I'll try to implement it and let see how it goes. :)

Again, thank you very much for the amazing support!
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get Script values before hand using Playmaker

Post by Tony Li »

Glad to help. If you have any questions about the script or events, just let me know!
Post Reply