Reputation: 12819
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.
Upvotes: 0
Views: 546
Reputation: 12819
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.
Upvotes: 1