Custom PlayMaker sequencer shortcut registration action doesn't work

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Custom PlayMaker sequencer shortcut registration action doesn't work

Post by Abelius »

Hi there,

So... I've made me a PlayMaker action to register shortcuts procedurally...

Code: Select all

using System;
using UnityEngine;
using HutongGames.PlayMaker;

namespace PixelCrushers.DialogueSystem.PlayMaker {
	
	[ActionCategory("Dialogue System")]
	[HutongGames.PlayMaker.TooltipAttribute("Registers a Sequencer shortcut in Dialogue System.")]
	public class RegisterSequencerShortcut : FsmStateAction {
		
	[RequiredField]
        [HutongGames.PlayMaker.TooltipAttribute("Unique shorcut name to be registered. Newer registrations with the same name will overwrite the previous.")]
        public FsmString shortcutName;

        [HutongGames.PlayMaker.TooltipAttribute("String of Sequencer commands to be registered as a shortcut.")]
        public FsmString shortcutValue;

        public override void Reset()
        {
            shortcutName = null;
            shortcutValue = null;
        }

        public override void OnEnter() {
            if (shortcutName != null)
            {
                // Remove braces if already entered
                shortcutName.Value.Replace("{{", "");
                shortcutName.Value.Replace("}}", "");

                // Add braces
                shortcutName.Value = "{{" + shortcutName.Value + "}}";

                // Register shortcut
                Sequencer.RegisterShortcut(shortcutName.Value, shortcutValue.Value);
            }
            Finish();
		}
	}
}
...but DS tells me "Unrecognized shortcut {{shortcutname}}" when testing the thing in a convo.

So, two things...

1.- For troubleshooting purposes, where could I read a list of the registered sequencer shorcuts at runtime?

2.- Am I getting this error because the action script is not located under the Dialogue Manager game object?

Thanks.
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom PlayMaker sequencer shortcut registration action doesn't work

Post by Tony Li »

Hi,

String.Replace() returns a string. It doesn't replace strings in-place. You'll want change those two Replace lines to:

Code: Select all

shortcutName.Value = shortcutName.Value.Replace("{{", "");
shortcutName.Value = shortcutName.Value.Replace("}}", "");
Abelius wrote: Thu Aug 05, 2021 1:20 pm1.- For troubleshooting purposes, where could I read a list of the registered sequencer shortcuts at runtime?

2.- Am I getting this error because the action script is not located under the Dialogue Manager game object?
No. The script can be anywhere. Maybe add a UnityEngine.Debug.Log() line to your PlayMaker action to log exactly what it's trying to register.

It would be a good idea to expose the list of registered shortcuts. Here's a patch:

DS_SequencerPatch_2021-08-05.unitypackage
(This will also be in version 2.2.19.)

It adds two properties: Sequencer.shortcuts and Sequencer.shortcutStack:

Code: Select all

        /// <summary>
        /// Registered shortcuts:
        /// </summary>
        public static Dictionary<string, string> shortcuts { get { return m_shortcuts; } }

        /// <summary>
        /// Stack of values for each shortcut. If adding a shortcut that already exists, the new
        /// value of the shortcut is added to the top of the stack. When removed, it's popped off
        /// the stack, revealing the previous value.
        /// </summary>
        public static Dictionary<string, Stack<string>> shortcutStack { get { return m_shortcutStack; } }
To check if a shortcut is registered:

Code: Select all

bool isFooRegistered = Sequencer.shortcuts.ContainsKey("Foo");
To list all registered shortcuts:

Code: Select all

foreach (string shortcutName in Sequencer.shortcuts.Keys)
{
    Debug.Log(shortcutName + " is a shortcut for: " + Sequencer.shortcuts[shortcutName]);
}
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Custom PlayMaker sequencer shortcut registration action doesn't work

Post by Abelius »

Hi Tony,

Dumb me for that mistake, lol.

I'm afraid I still have the problem, though, as the shortcut name that gets registered is still the correct one (theoretically).

Image
Image

I've also waited five seconds to trigger the convo, in case this was a timing issue (not getting registered before I start it).

So, I'll install that package and troubleshoot further. Thank you for that!
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Abelius
Posts: 318
Joined: Fri Jul 21, 2017 12:45 pm

Re: Custom PlayMaker sequencer shortcut registration action doesn't work

Post by Abelius »

Okay, maybe I need a rest or something. Look at what I was doing, lol...

Image

I was adding the braces two times. One in PlayMaker when building the name string, and another one in the script.

So it's working nicely now. Thank you for the list method. I doubt I would have figured it out without it. :P
Unity 2019.4.9f1
Dialogue System 2.2.15
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom PlayMaker sequencer shortcut registration action doesn't work

Post by Tony Li »

Glad to help!
Post Reply