[alicebot-general] Re: If statements in JavaScript within AIML

Alan Haymes a.haymes at nicobloc.com
Thu Apr 20 01:53:27 PDT 2006


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. 




More information about the alicebot-general mailing list