0

I've got a simple bot game I'm developing. It has a Root Dialog, which can take you to two others - A Start Dialog and a Join Dialog.

Join Dialog can lead to the Play Game Dialog, which when the game is over leads you to a Score Dialog. Feels like a lot bot (sic) but it runs smoothly. When scoring is done, I'd like to get back to the Root Dialog for another round.

But I'm stuck.

Even though I issue both an EndDialog() activity and a CodeAction() activity that simply calls DialogContext.CancelAllDialogs(), I remain within what looks like the EndDialog and therefore I don't get back to Root. Thus, I can't restart my game. Is there something I'm missing? I'm using both Adaptive Dialogs as well as Adaptive Cards and Hero Cards. Although, I don't think the cards should matter.

Irwin
  • 12,551
  • 11
  • 67
  • 97
  • Can you please provide some code for troubleshooting, specifically your root dialog, what you are doing at the conclusion of your dialogs, and possibly how you are transitioning between Join/Play/Score dialogs? – billoverton Jun 11 '20 at 20:17
  • Specifically, I set AutoEndDialog = false, to control dialog end based on the flow of my game. So, I may not have been cleaning up after myself properly. – Irwin Jun 12 '20 at 01:39

1 Answers1

1

So, this is what I ended up doing to get what I want. It might not be the best way, but it works:

I created a CodeAction dialog that runs when the message I want to trigger a round restart to come in - there's a specific intent that is tied to that. The CodeAction calls this method:

private async Task<DialogTurnResult> CancelAndReturnToRoot(DialogContext dc, object options)
{
        var lastDialog = dc;
        var secondToLastDialog = lastDialog;
        var journeysUp = 1;
        while (lastDialog != null)
        {
            lastDialog = lastDialog.Parent;
            if (lastDialog != null)
                secondToLastDialog = lastDialog;
            journeysUp++;
        }

        return await secondToLastDialog.CancelAllDialogsAsync();
}

This seems to release the dialogs that I created and let me get back to the beginning dialog.

Irwin
  • 12,551
  • 11
  • 67
  • 97