Are sequences without an @number guaranteed to play without interruption?

Announcements, support questions, and discussion for the Dialogue System.
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Are sequences without an @number guaranteed to play without interruption?

Post by AoF »

I've got a really random bug that 20% of the people who play my game report, and as far as I can tell, it seems like it shouldn't be possible to occur (this is usually the case with tough bugs). I'm starting to think it could be a race condition, or caused by a lack of understanding on the dialogue library.

I'm looking at my dialogue, and one node looks like this:

My question is, is it possible to click really fast and skip these sequences/scripts, or are they guaranteed to execute until completion?

Here's my CollectCrops() function:

Code: Select all

namespace PixelCrushers.DialogueSystem.SequencerCommands
{

    public class SequencerCommandCollectCrops : SequencerCommand
    {

        public void Start()
        {
            // Add your initialization code here. You can use the GetParameter***() and GetSubject()
            // functions to get information from the command's parameters. You can also use the
            // Sequencer property to access the SequencerCamera, CameraAngle, Speaker, Listener,
            // SubtitleEndTime, and other properties on the sequencer. If IsAudioMuted() is true, 
            // the player has muted audio.
            //
            // If your sequencer command only does something immediately and then finishes,
            // you can call Stop() here and remove the Update() method:
            //
            string cropName = DialogueLua.GetVariable("GrowingCropName").AsString;
            string nameOfVariable = null;
            switch (cropName)
            {
                case "sunflowers":
                    nameOfVariable = "sunflowers";
                    break;
                case "catnip":
                    nameOfVariable = "catnip";
                    break;
                case "wheat":
                    nameOfVariable = "wheat";
                    break;
                case "coffee beans":
                    nameOfVariable = "coffeebeans";
                    break;
                case "carrots":
                    nameOfVariable = "carrots";
                    break;
                default:
                    throw new System.Exception("Unknown crop name: " + cropName);
            }

            var previousNumberOfCrop = DialogueLua.GetVariable(nameOfVariable).AsInt;
            DialogueLua.SetVariable(nameOfVariable, previousNumberOfCrop + 1);

            var previousCropsGrown = DialogueLua.GetVariable("cropsGrown").AsInt;
            DialogueLua.SetVariable("cropsGrown", previousCropsGrown + 1);

            DialogueLua.SetVariable("DayCropReady", -1);
            DialogueLua.SetVariable("GrowingCropName", "");
            Stop();
        }
    }
}
BTW: If that exception were thrown, it would cause this, so this is most likely the source of the bug, but I can't figure out any possible way for it to get to that default block.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Are sequences without an @number guaranteed to play without interruption?

Post by Tony Li »

Can you try the following?

1. Move your code from "public void Start()" to "public void OnDestroy()" and remove the Stop(); line.

2. Change the Start() method to simply call Stop().

Code: Select all

namespace PixelCrushers.DialogueSystem.SequencerCommands
{

    public class SequencerCommandCollectCrops : SequencerCommand
    {

        public void Start()
        {
            Stop();
        }
		
        public void OnDestroy()
        {
            string cropName = DialogueLua.GetVariable("GrowingCropName").AsString;
            string nameOfVariable = null;
            switch (cropName)
            {
                case "sunflowers":
                    nameOfVariable = "sunflowers";
                    break;
                case "catnip":
                    nameOfVariable = "catnip";
                    break;
                case "wheat":
                    nameOfVariable = "wheat";
                    break;
                case "coffee beans":
                    nameOfVariable = "coffeebeans";
                    break;
                case "carrots":
                    nameOfVariable = "carrots";
                    break;
                default:
                    throw new System.Exception("Unknown crop name: " + cropName);
            }

            var previousNumberOfCrop = DialogueLua.GetVariable(nameOfVariable).AsInt;
            DialogueLua.SetVariable(nameOfVariable, previousNumberOfCrop + 1);

            var previousCropsGrown = DialogueLua.GetVariable("cropsGrown").AsInt;
            DialogueLua.SetVariable("cropsGrown", previousCropsGrown + 1);

            DialogueLua.SetVariable("DayCropReady", -1);
            DialogueLua.SetVariable("GrowingCropName", "");
        }
    }
}
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: Are sequences without an @number guaranteed to play without interruption?

Post by AoF »

Sure, I can do that, but I can't reproduce this bug on my own, so I think the only way I can tell if this fixes the issue is for me to send it to a bunch of people and wait to see if the bug is ever reported again.

What do these changes do? I have other custom sequences and I'm not sure if I should be changing them the same way.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Are sequences without an @number guaranteed to play without interruption?

Post by Tony Li »

The Start() method should always run the way it's set up in the Dialogue System, but maybe in some weird universe the script is getting destroyed before Start() can run. OnDestroy() always runs.

Are you sure the variable "GrowingCropName" is set to a valid value before this sequence runs?
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: Are sequences without an @number guaranteed to play without interruption?

Post by AoF »

I'm not sure of that. In fact, I think the bug is that it's set to an invalid value before the sequence runs. The problem is, I can't see any possible way for it to be set to an invalid value. The only places in my code that set that variable are in this sequence, or in the conversation "Field/Eva" nodes 14-18. If you want to look in my actual project, you can use the link I emailed you last for support to see (this is very old code that hasn't been changed in a while).
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: Are sequences without an @number guaranteed to play without interruption?

Post by AoF »

Maybe this'll save you some time? These are the only places in my whole codebase that use that variable:

Code: Select all

Assets/Scripts/Dialogue Database.asset
843-  - id: 4
844-    fields:
845-    - title: Name
846:      value: GrowingCropName
847-      type: 0
848-      typeString:
849-    - title: Initial Value
--
12877-        isConnector: 0
12878-        priority: 2
12879-      conditionsString:
12880:      userScript: Variable["GrowingCropName"] = "sunflowers"
12881-      onExecute:
12882-        m_PersistentCalls:
12883-          m_Calls: []
--
12954-        isConnector: 0
12955-        priority: 2
12956-      conditionsString:
12957:      userScript: Variable["GrowingCropName"] = "catnip"
12958-      onExecute:
12959-        m_PersistentCalls:
12960-          m_Calls: []
--
13031-        isConnector: 0
13032-        priority: 2
13033-      conditionsString:
13034:      userScript: Variable["GrowingCropName"] = "wheat"
13035-      onExecute:
13036-        m_PersistentCalls:
13037-          m_Calls: []
--
13108-        isConnector: 0
13109-        priority: 2
13110-      conditionsString:
13111:      userScript: Variable["GrowingCropName"] = "coffee beans"
13112-      onExecute:
13113-        m_PersistentCalls:
13114-          m_Calls: []
--
13185-        isConnector: 0
13186-        priority: 2
13187-      conditionsString:
13188:      userScript: Variable["GrowingCropName"] = "carrots"
13189-      onExecute:
13190-        m_PersistentCalls:
13191-          m_Calls: []
--
15655-        type: 0
15656-        typeString: CustomFieldType_Text
15657-      - title: Dialogue Text
15658:        value: Your [var=GrowingCropName] will be ready on day [var=DayCropReady].
15659-        type: 0
15660-        typeString: CustomFieldType_Text
15661-      - title: Parenthetical
--
15892-        type: 0
15893-        typeString: CustomFieldType_Text
15894-      - title: Dialogue Text
15895:        value: You've grown some wonderful [var=GrowingCropName]!
15896-        type: 0
15897-        typeString: CustomFieldType_Text
15898-      - title: Parenthetical
--
17491-        isConnector: 0
17492-        priority: 2
17493-      conditionsString: CurrentQuestState("The girl in the alley") == "active" and
17494:        (CurrentQuestEntryState("The girl in the alley", 3) == "active") and (Variable["GrowingCropName"]
17495-        == "catnip")
17496-      userScript:
17497-      onExecute:

Assets/Scripts/SequencerCommandCollectCrops.cs
11-
12-        public void OnDestroy()
13-        {
14:            string cropName = DialogueLua.GetVariable("GrowingCropName").AsString;
15-            string nameOfVariable = null;
16-            switch (cropName)
17-            {
--
41-            DialogueLua.SetVariable("cropsGrown", previousCropsGrown + 1);
42-
43-            DialogueLua.SetVariable("DayCropReady", -1);
44:            DialogueLua.SetVariable("GrowingCropName", "");
45-        }
46-    }
47-}

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

Re: Are sequences without an @number guaranteed to play without interruption?

Post by Tony Li »

I'll research this and reply back here later today.
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: Are sequences without an @number guaranteed to play without interruption?

Post by AoF »

Cool, thanks!
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Are sequences without an @number guaranteed to play without interruption?

Post by Tony Li »

There's a window of a fraction of a frame in which Start() might not be called if a continue has already been queued up somehow. Moving your code OnDestroy() will take care of that, if that's the issue.

In the next release, I'll make a change so you can use Awake() instead of Start() for custom sequencer commands. That way you don't have to use OnDestroy(). I need to make a small change to the sequencer to support that, though. I'll also change the commented starter template to use Awake() instead of Start().

Another solution that's guaranteed to always run is to use a custom Lua function instead of a custom sequencer command. Lua functions run entirely outside of the whole view/UI/sequencer piece.
AoF
Posts: 241
Joined: Sun May 12, 2019 8:36 pm

Re: Are sequences without an @number guaranteed to play without interruption?

Post by AoF »

Tony Li wrote: Sat Jul 06, 2019 4:25 pm There's a window of a fraction of a frame in which Start() might not be called if a continue has already been queued up somehow. Moving your code OnDestroy() will take care of that, if that's the issue.
Do you think it's possible for a human to be able to cause this?

A player who experienced this bug should have a log for me later today.
Post Reply