[alicebot-general] Re: If statements in JavaScript within AIML
Dr. Rich Wallace
drwallace at alicebot.org
Fri Apr 21 06:12:28 PDT 2006
It is a bit of a quirk on AIML that there is no easy way to test equality
of two predicates with unknown values.
This is one place I wouldn't mind seeing some "Embrace and Extend". The
<condition> tag is the obvious choice for modification. If an <li>
element could access another predicate, for example
<li equals="newname">
Then your problem would be solved.
I've been wracking my brain trying to come up with a clever AIML solution
using <srai>, but maybe Kim can think of one where I can't.
>
> I think I noticed a bit of a quirk when using javascript inside a
> <template>.
>
> Ideally I wanted to use the condition tag to test whether predicate "name"
> was equivalent to another predicate, "newname", and if so tell the client
> that they had already told the bot that. If "name" was different to
> "newname" then I would give them the option to change "name" to "newname".
>
> Finding that I couldn't do <condition name="name" value="<get
> name="newname"/>"> (I tried all variations I could think off - is there a
> way?) - I resorted to some javascript which basically checks first whether
> "name" has been set and if not sets "name" to <star/>, else if "name" is
> the
> same as <star/> it says that it knows this already and finally if they are
> different it gives the client the choice to change it by setting the topic
> name to 'changename' so that it can catch various yes and no answers in
> other categories. The script is as follows:
>
>
> <pattern>CALL ME *</pattern>
> <template>
> <script>
> if (!"<get name="name"/>")
> {
> document.write ("Hello <set name="name"><star/></set>.");
> }
> else if ("<star/>" == "<get name="name"/>")
> {
> document.write ("You already told me your name was <get name="name"/>.");
> }
> else if ("<star/>" != "<get name="name"/>")
> {
> document.write ("You already told me your name was <get name="name"/>. Do
> you want to change it to <star/>?
> <think><set name="topic">changename</set></think>");
> }
> </script>
>
>
> The problem I discovered is that whereas the IF conditions work fine, the
> AIML executes all the <set> instructions irrespective of the IF conditions
> so that it will always set "name" = <star/> and "topic" = "changename".
>
> Therefore I didn't achieve my objective this way. Is there a simpler way
> to
> do this anyway?
>
> Thanks
>
> Alan Haymes.
>
>
> _______________________________________________
> This is the alicebot-general mailing list
> Reply to alicebot-general at list.alicebot.org
> Unsubscribe and change preferences at
> http://list.alicebot.org/mailman/listinfo/alicebot-general
> Learn netiquette at http://www.dtcc.edu/cs/rfc1855.html
> Learn to read at http://www.literacy.org/
>
More information about the alicebot-general
mailing list