Ok, let’s look at this in terms of a quiz. when the chatbot asks a question that requires one of several answers, you’ll need to set up the AIML categories in a certain way. The following example is one way to do just that. What you have for your example isn’t the best way to start out due to some issues with the code (I’ll address that at the end of this post), so I’ll post code that I feel will serve your needs best:
<category>
<pattern>HELLO</pattern>
<template>Hello! Would you like to take a short quiz?</template>
</category>
<category>
<pattern>NO</pattern>
<that>* TAKE A SHORT QUIZ</that>
<template>
<!-- add a response here to handle a "no" answer -->
</template>
</category>
<category>
<pattern>*</pattern>
<that>* TAKE A SHORT QUIZ</that>
<template>
<!-- add a response here to handle any inputs that are neither yes nor no -->
</template>
</category>
<category>
<pattern>YES</pattern>
<that></that>
<template>
<srai>QUIZQUESTION1</srai>
</template>
</category>
<category>
<pattern>QUIZQUESTION1</pattern>
<template>
please choose the occasion:
XXX1
XXX2
XXX3
</template>
</category>
<category>
<input>*</input>
<that>PLEASE CHOOSE THE OCCASION *</that>
<template>
<think>
<set name="QQ1ANSWER"></star></set>
<set name="NEXTQUESTION">QUIZQUESTION2</set>
</think>
<condition name="QQ1ANSWER">
<li value="XXX1"><!-- handle response for condition XXX1 here --></li>
<li value="XXX2"><!-- handle response for condition XXX2 here --></li>
<li value="XXX3"><!-- handle response for condition XXX3 here --></li>
<li value="quit">
<!-- this is included in case the user wants to exit the quiz -->
<think><set name="NEXTQUESTION">QUIZABORT</set></think>
</li>
<li>
<think><set name="NEXTQUESTION">QUIZQUESTION1</set></think>
I am sorry, but I do not understand what you mean by that. Please try again.
</li>
</condition>
<srai><get name="NEXTQUESTION"></srai>
</template>
</category>
<category>
<pattern>QUIZQUESTION2</pattern>
<template>
<!-- the second question to be asked will go here, with answers handled just like QUIZQUESTION1, above -->
</template>
</category>
<category>
<pattern>QUIZABORT</pattern>
<template>
<!-- abort the quiz -->
</template>
</category>
There are other ways of doing this, but this way is compact, fairly easy to follow, and works pretty well. The idea is simple, really. The code creates a linear progression that only advances when an expected input is given, looping back on itself if an unexpected input is seen. I’ve added an “escape clause” to the code to show how that’s handled as well. Additional questions are handled in exactly the same manner, with the exception of the last question, but that’s something that I didn’t cover here because I don’t wish to do ALL of your homework for you.
Now let’s move on to something else for a moment. I’m sure that you noticed that my AIML code (and now the AIML code that you also posted) sits within a grey “box”, and that all of the code is visible. This is because I’ve surrounded the AIML code with [code] tags. This is done for a very important reason. The forum software used here does not allow certain HTML/XML tags to be displayed in order to prevent malicious code execution, and the <pattern> tag (among others) is among these “forbidden” tags. The only reason you see it here, outside of [code] tags is because I know how to get around this. The “how” of that is unimportant, so I won’t get into it. The bottom line here is that any AIML, HTML, PHP, JavaScript or any other type of code needs to be placed within [code] tags in order for it to be properly displayed. It’s a really good habit to get into, so I encourage you to start now.
Ok, now that that’s done, let’s move on to the original AIML code that you posted. I feel that I need to point out that nearly ALL AIML interpreters are very literal and strict when it comes to the contents of <pattern>, <that> and <topic> tags. The extra spaces that you’ve added surrounding the word HELLO in your <pattern> tag will produce unexpected results if left there. there can be no leading or trailing spaces within the tags I mentioned unless you intend the user to make use of such spaces in their inputs, and that’s an unreasonable expectation. Thus, this:
<pattern> HELLO </pattern>
should look like this, instead:
<pattern>HELLO</pattern>
The difference is subtle to the eye, but it’s VERY important to remember.
I hope this helps.