Pre and Post Typewriter Sequences?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Pre and Post Typewriter Sequences?

Post by CodePrincess »

Hi!

I need to show a gif at the start of a dialogue node and a different one at the end of the node's typewriter sequence.

I went to the Sequence panel and entered:

Code: Select all

[lua(HideGif(Variable["Cheerful_Maya"]))]
[lua(ShowGif(Variable["Thoughtful_Maya_Talking"]))]
Delay({{end}})
[lua(ShowGif(Variable["Thoughtful_Maya"]))]
[lua(HideGif(Variable["Thoughtful_Maya_Talking"]))]
But I got this error:
Dialogue System: Syntax error 'Expected '('' at column 1 row 2 parsing: nil
nil
Delay(2)
nil
nil
I think the syntax is okay, but am I even on the right track?

Thank you for your help!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Pre and Post Typewriter Sequences?

Post by Tony Li »

Hi,

Unlike Lua, sequences require semicolons between commands like C# does. Try this:

Code: Select all

[lua(HideGif(Variable["Cheerful_Maya"]))];
[lua(ShowGif(Variable["Thoughtful_Maya_Talking"]))];
Delay({{end}});
[lua(ShowGif(Variable["Thoughtful_Maya"]))];
[lua(HideGif(Variable["Thoughtful_Maya_Talking"]))]
Better yet, try this:

Code: Select all

[lua(HideGif(Variable["Cheerful_Maya"]))];
[lua(ShowGif(Variable["Thoughtful_Maya_Talking"]))];
required [lua(ShowGif(Variable["Thoughtful_Maya"]))]@{{end}};
required [lua(HideGif(Variable["Thoughtful_Maya_Talking"]))]@{{end}}
I made two changes:
  • Removed Delay and added "@{{end}}" to the last two commands. Sequencer commands will all try to run at the beginning of the sequence unless you specify some kind of timing using "@".
  • Added "required" in front of the last two commands. This ensures they run even if the player cancels the subtitle before the {{end}} time is reached.

You may find it simpler to write custom sequencer commands for ShowGif and HideGif that would parallel your custom Lua functions. Sequencer commands are actually easier to write than Lua functions. This way you could shorten your Sequence to something like:

Code: Select all

HideGif(Cheerful_Maya);
ShowGif(Thoughtful_Maya_Talking);
required ShowGif(Thoughtful_Maya)@{{end}};
required HideGif(Thoughtful_Maya_Talking)@{{end}}
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Pre and Post Typewriter Sequences?

Post by CodePrincess »

Is it possible to make a custom sequencer script that takes parameters? Do I need to attach the finished script to a game object for it to work?

Thank you again!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Pre and Post Typewriter Sequences?

Post by Tony Li »

Hi,
CodePrincess wrote: Sat Oct 27, 2018 5:29 pmIs it possible to make a custom sequencer script that takes parameters?
Yes, as many parameters as you want. In the Start() method, read parameters using GetParameter(#) where # is the parameter number, starting from 0. This will return the parameter's string value. To get bool, int, or float values, use GetParameterAsType(#) such as GetParameterAsBool(#). You can also use GetSubject(#), which will return a transform. The API reference is here. Here are some examples:

Code: Select all

// Command syntax: MyCommand(gameObjectName, onOrOff)
//Example: MyCommand(Camera, false)
void Start() {
    Transform subject = GetSubject(0);
    bool onOrOff = GetParameterAsBool(1);
    if (subject != null)
    {
        subject.gameObject.SetActive(onOrOff);
    }
    Stop();
}
CodePrincess wrote: Sat Oct 27, 2018 5:29 pm Do I need to attach the finished script to a game object for it to work?
No. The Dialogue System will automatically find it in your project as needed.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Pre and Post Typewriter Sequences?

Post by CodePrincess »

Awesome!

... How do I.... get the animated gifs in there? I don't know how to do it without SerializeField.

Thank you again!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Pre and Post Typewriter Sequences?

Post by Tony Li »

One way is to give your animated gif GameObjects unique names, and find them by GameObject name:

Code: Select all

// Command syntax: PlayGif(gameObjectName)
void Start() {
    Transform subject = GetSubject(0);
    if (subject != null)
    {
        OldMoatGames.AnimatedGifPlayer gifPlayer = subject.GetComponent<OldMoatGames.AnimatedGifPlayer>();
        if (gifPlayer != null)
        {
            gifPlayer.Play();
        }
    }            
    Stop();
}
Example Sequence:
  • Sequence: PlayGif(MyGifObject)
Or, if you want to use your GifManager class from your other thread, you could pass a number:

Code: Select all

// Command syntax: PlayGif(index)
void Start() {
    int index = GetParameterAsInt(0);
    GifManager manager = FindObjectOfType<GifManager>();
    manager.Gif[index].enabled = true;
    Stop();
}
Example Sequence:
  • Sequence: PlayGif(3)
You can include variable values in Sequence fields using the [var=varName] tag. So you could do this:
  • Sequence: PlayGif([var=Cheerful_Maya])
(Replace blank spaces with underscores here.)
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Pre and Post Typewriter Sequences?

Post by CodePrincess »

Okay, at this point, I feel like I owe you a present. Maybe a gif player plugin, or some music tracks?

I've got my sequencer command code here:

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using OldMoatGames;
using PixelCrushers.DialogueSystem;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandHideGif : SequencerCommand
    {
        public void Start()
        {
            // Command syntax: HideGif(index)
            int index = GetParameterAsInt(0);
            GifManager manager = FindObjectOfType<GifManager>();
            manager.Gif[index].enabled = false;
            Stop();
        }
    }
}

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using OldMoatGames;
using PixelCrushers.DialogueSystem;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandShowGif : SequencerCommand
    {
        public void Start()
        {
            // Command syntax: HideGif(index)
            int index = GetParameterAsInt(0);
            GifManager manager = FindObjectOfType<GifManager>();
            manager.Gif[index].enabled = true;
            Stop();
        }
    }
}
And this is how I use the commands in the Sequencer field:

Code: Select all

HideGif([var=Cheerful_Maya]);
ShowGif([var=Thoughtful_Maya_Talking]);
required ShowGif([var=Thoughtful_Maya]])@{{end}};
required HideGif([var=Thoughtful_Maya_Talking])@{{end}};

The calls don't generate any errors, but they don't show/hide any gifs either.

:oops:
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Pre and Post Typewriter Sequences?

Post by Tony Li »

Hmm, they seem to work in this test: GifTest_2018-10-29.unitypackage

I added two lines of code to each: (1) Shows a debug message, and (2) Activates/deactivates the GameObject in addition to enabling/disabling the gif player component.

You'll want to import import the test in a separate project. Otherwise the scripts will conflict with yours that have the same name.
Post Reply