コード例 #1
0
        private IUpdateEvent ChoiceHandler(ref EventArgs ea, IDictionary <string, object> globals)
        {
            IChoice ic  = (IChoice)ea;
            var     idx = ic.GetChoiceIndex();

            ea = null;

            if (idx < 0 || idx >= scheduler.prompt.Options().Count)
            {
                // bad index, so reprompt for now
                ChatRuntime.Info("Invalid index " + idx + ", reprompting\n");
                //scheduler.prompt.Resolve(globals); // re-resolve
                return(new UpdateEvent(scheduler.prompt.Resolve(globals)));
            }
            else
            {
                Opt opt = scheduler.prompt.Selected(idx);


                if (opt.action != Command.NOP)
                {
                    // We've gotten a response with a branch, so finish & take it
                    scheduler.Completed(false);
                    opt.action.Resolve(globals);
                    runtime.FindAsync((Find)opt.action); // find next
                }
                else
                {
                    scheduler.chat = scheduler.prompt.parent; // just continue
                }
                return(null);
            }
        }
コード例 #2
0
        private IUpdateEvent ChoiceHandler(ref EventArgs ea, IDictionary <string, object> globals)
        {
            IChoice ic  = (IChoice)ea;
            var     idx = ic.GetChoiceIndex();

            ea = null;

            if (idx < 0 || idx >= scheduler.prompt.Options().Count)
            {
                // bad index, so reprompt for now
                ChatRuntime.Info("Invalid index " + idx + ", reprompting\n");

                return(new UpdateEvent(scheduler.prompt.Resolve(globals)));
            }
            else
            {
                Opt opt = scheduler.prompt.Selected(idx);

                if (opt.action != Command.NOP)
                {
                    // We've gotten a response with a branch, so finish & take it
                    scheduler.Completed(false);
                    opt.action.Resolve(globals);
                    runtime.FindAsync((Find)opt.action); // find next

                    // Question: if the Chat is unfinished (and resumable)
                    // shouldn't we return to it later? See #154
                }
                else
                {
                    // No action chosen so continue the current chat
                    scheduler.Resume();
                }

                return(null);
            }
        }