how to set a conversation entry as uncancelable?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Arcanor
Posts: 81
Joined: Sun Oct 05, 2014 4:20 am

how to set a conversation entry as uncancelable?

Post by Arcanor »

There are some places in my game where having a user cancel the conversation would be bad. For example, in my narrative intro dialogue. The conversation is automatically started by my game manager class, and if it is canceled by the user, the rest of the game simply won't start, because the first gameplay scene is triggered from within the dialogue entries.

I believe what I need to do is to temporarily prevent the user from inputting the "cancel" or "cancel conversation" key or button.

I looked through the available sequencer commands, but I didn't see anything that might be useful in doing so.

Is there already a suggested method to do this? Or should I create my own new Lua.RegisterFunction to change the values in DialogueManager.Instance.displaySettings.inputSettings.cancel.key (and the others) to "None" and then back again later?

Thanks!
Arcanoria Games - http://www.arcanoria.com - indie game development blog
twitter: https://twitter.com/WaltCollins3 @WaltCollins3
Game titles: Pesticide Patrol, Arcanoria Chronicles, CyberGhost, Arcanoria
PLAY NOW: http://arcanor.itch.io/
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: how to set a conversation entry as uncancelable?

Post by Tony Li »

Nothing is built in to do this. What you described will work. You could also write a small script that implements OnConversationStart and OnConversationEnd, and add it to any GameObjects that trigger uncancelable conversations. In OnConversationStart, set cancel.key to string.Empty. In OnConversationEnd, set cancel.key back.

Or write a sequencer command similar to the built-in SetContinueMode command. There's a template in Scripts/Templates/SequencerCommandTemplate.cs.
Arcanor
Posts: 81
Joined: Sun Oct 05, 2014 4:20 am

Re: how to set a conversation entry as uncancelable?

Post by Arcanor »

I've done as you suggested, and created a custom sequencer command to do this. It mostly works correctly (see below).

Here is my code (based on your template of course!):

Code: Select all

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

namespace PixelCrushers.DialogueSystem.SequencerCommands 
{
    public class SequencerCommandSetCancelable : SequencerCommand 
    {
	    public void Start() 
        {
            bool _enable = GetParameterAsBool(0);
            DialogueManager.Instance.displaySettings.inputSettings.cancel.key = (_enable ? KeyCode.Escape : KeyCode.None);
            DialogueManager.Instance.displaySettings.inputSettings.cancelConversation.key = (_enable ? KeyCode.Escape : KeyCode.None);
            Stop();
        }
    }
}
The only slight issue I'm having with this code is that it doesn't seem to take effect until the FOLLOWING dialogue is shown. So I basically have to place it before the entry that I want to start being uncancelable. In my game, that means I have to start the game with the escape keys set to None, since I want the very first dialogue entry to be uncancelable. Not a big problem, but I just wanted anyone else who might be using this code to be aware.

One other thing I should mention is that I've hard-coded the escape key, which effectively makes the dialogue manager's keycode settings ignored after this sequence is run (i.e. inputSettings.cancel.key and inputSettings.cancelConversation.key). Sorry for that, but I didn't feel like caching the prior value, which would have required putting it somewhere global, and that seemed like a lot of extra added trouble.
Arcanoria Games - http://www.arcanoria.com - indie game development blog
twitter: https://twitter.com/WaltCollins3 @WaltCollins3
Game titles: Pesticide Patrol, Arcanoria Chronicles, CyberGhost, Arcanoria
PLAY NOW: http://arcanor.itch.io/
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: how to set a conversation entry as uncancelable?

Post by Tony Li »

The only slight issue I'm having with this code is that it doesn't seem to take effect until the FOLLOWING dialogue is shown. So I basically have to place it before the entry that I want to start being uncancelable.
I'm glad it's working with your workaround, but off the top of my head I don't know why it takes effect in the following dialogue. I'll dig into the code and reply back here if I figure it out.
Post Reply