Page 1 of 1

Playing sequence from a script

Posted: Sat May 13, 2023 9:04 am
by thecodehermit
I have a C# function. It is registered with lua and I play that script inside a conversation node. I want to play a continue sequence through that script.
Here is my C# code

Code: Select all

 DialogueManager.instance.PlaySequence("Continue();"); 
the problem is the code doesn't do anything. I also tried alert sequence just to test. But it also didn't show anything.

Code: Select all

 DialogueManager.instance.PlaySequence("ShowAlert(22222);"); 
What am I doing wrong here ?

Re: Playing sequence from a script

Posted: Sat May 13, 2023 10:31 am
by Tony Li
Hi,

In the first case, you can continue more directly:

Code: Select all

DialogueManager.instance.OnContinue();
In the second one, use quotes:

Code: Select all

DialogueManager.instance.PlaySequence("ShowAlert(\"22222\");"); 
Or, more directly:

Code: Select all

DialogueManager.ShowAlert("22222");

Re: Playing sequence from a script

Posted: Sat May 13, 2023 12:53 pm
by thecodehermit
Ok for some reason now it fires the version with and without quotes without a problem.... Not sure what I did, but at least it works O_o

Code: Select all

DialogueManager.instance.PlaySequence("ShowAlert(22222);"); 
DialogueManager.instance.PlaySequence("ShowAlert(\"22222\");"); 
Though this one is giving an error

Code: Select all

 DialogueManager.instance.OnContinue(); 
"DialogueSystemController does not contain a definition of 'OnContinue' and no accessible extension method....... "

I guess it needs a reference, or maybe you added that function in a new version ?

Also do you know why wouldnt this do anything ?

Code: Select all

DialogueManager.instance.PlaySequence("Continue();"); 
As far as I know this should run the continue sequence. I just want to know what the problem is so I wont have issues calling other sequences.

Re: Playing sequence from a script

Posted: Sat May 13, 2023 2:44 pm
by Tony Li
Geez, sorry, I totally answered wrong on everything this morning.

1. You were playing a sequence, not running a Lua script, so you do not need quotes. This line of yours is totally valid:

Code: Select all

DialogueManager.instance.PlaySequence("ShowAlert(22222);");
2. "DialogueManager.instance.OnContinue();" should have been:

Code: Select all

DialogueManager.standardDialogueUI.OnContinue();
3. DialogueManager.instance.PlaySequence("Continue();"); should work if only one conversation is currently active. Otherwise you can use Continue(all) to continue all active conversations. If this still isn't working, are there any errors or warnings in the Console window?

Re: Playing sequence from a script

Posted: Sat May 13, 2023 3:23 pm
by thecodehermit
Don't worry about it. My brain sometimes goes on strike too when I overwork it xD

I didn't even knew it was possible to run multiple conversations at the same time.
I run a single conversation. The continue works as expected when I manually put Continue() in the sequence field in the conversation node.
Though, none of the following work through the lua registered C# function.

Code: Select all

DialogueManager.standardDialogueUI.OnContinue();
DialogueManager.instance.PlaySequence("Continue();");
DialogueManager.instance.PlaySequence("Continue(all);");
I put a few debug logs and they show up, so the problem isnt in the function itself.
I also ran the alerts and few other sequences and they also work as expected while being called from inside the c# function.

When I start unity I have few warnings from other plugins, but none are related to Pixelcrushers. And no warnings or errors appear when I run the conversation or the c# function.

I just don't get it why the Continue sequence just wont fire when everything else does...
The only other thing I can think of is to make a new project, get the same version of the dialogue system (if that is even possible) and test the same conversation and see if the function runs there. Though setting and testing that will take hours. And even if it works there I still wouldn't know what the actual problem is. So I was hoping you could have an idea why just the Continue isn't working.

Re: Playing sequence from a script

Posted: Sat May 13, 2023 3:47 pm
by thecodehermit
Ok I think I found where the problem is. Maybe...
I dont know if you remember but last year you wrote a custom sequence for me:

Code: Select all

using UnityEngine;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandAudioWaitOrContinue : SequencerCommandAudioWait
    {
        protected override void TryAudioClip(string audioClipName)
        {
            int actor_ID = DialogueManager.CurrentConversationState.subtitle.dialogueEntry.ActorID;
            Actor actor = DialogueManager.masterDatabase.GetActor(actor_ID);
 
            if (!actor.IsPlayer) {
                base.TryAudioClip(audioClipName);
                if (!(playedAudio || string.IsNullOrEmpty(DialogueManager.currentConversationState.subtitle.formattedText.text))) {
                    var previousContinueMode = DialogueManager.displaySettings.subtitleSettings.continueButton;
                    DialogueManager.displaySettings.subtitleSettings.continueButton = DisplaySettings.SubtitleSettings.ContinueButtonMode.Always;
                    DialogueManager.conversationView.SetupContinueButton();
                    DialogueManager.displaySettings.subtitleSettings.continueButton = previousContinueMode;
                }
            } else {
                Stop();
            }
        }
    }
}

so this thing runs at every conversation node like this:

Code: Select all

AudioWaitOrContinue(entrytag)->Message(Spoke);
My_Delay(1)@Message(Spoke);
I guess this is what is messing with the continue button ? I cant really test it because when I remove that code the conversation automatically moves forward after some time. So I cant tell if my continue script is working or its the default behavior...

As to the purpose of the sequence above. As far as remember it enables a manual continue button. And also it doesn't automatically continue when the conversation audio finishes. Or something on those lines...

Re: Playing sequence from a script

Posted: Sat May 13, 2023 4:03 pm
by Tony Li
Hi,

The OnContinue() method should still continue even if other sequencer commands are running. Here's a test scene that you can compare to your setup:

DS_CodeHermitTestContinue_2023-05-13.unitypackage

Re: Playing sequence from a script

Posted: Sat May 13, 2023 4:37 pm
by thecodehermit
I used your code and the following works, somehow ...

Code: Select all

    void ContinueNow() {
        DialogueManager.standardDialogueUI.OnContinue();
    }
    
    void Test_Script_Func() {
         Invoke(nameof(ContinueNow), 0.1f);
    } 
The delay makes the continue work. Though I have no idea why -_-
I just set the delay to 0.1 sec and I am good to go I guess xD
Thanks for the help and sorry for the bother.

Re: Playing sequence from a script

Posted: Sat May 13, 2023 5:28 pm
by Tony Li
The Script runs just before showing the subtitle, so it runs before the continue button is set up. If you want to call Continue() from a Script, you'll need to wait for the end of the next frame (or 0.1 seconds is fine if that works for you).