AI - Adding Extras

Some extras to add to your chatbot

1.  "Load File" button - to reload your word file automatically

    This will reload your file "myChatbot.txt"
1. Add a button - name it "Load File"
2. on it's script put:

on mouseUp
    openCard
on mouseUp


2.  "Load File" button - to ask for a file to load.

    This will allow you to load different lists
1. Add a button - name it "Load File"
2. on it's script put:

on mouseUp
    openCard
on mouseUp

3. on the card script, change the openCard handler

OLD:
on openCard
   put specialFolderPath("Desktop") & "/" & "mychatbot.txt" into myFile
   put URL ( "file:" & myFile ) into myList 
   put "Hello, Let's talk" & return into field "log"
   select before line 1 of  field "input"              // put the cursor at the start of the field
end openCard
NEW:
on openCard
   answer file "Pick a word file:"
   put it into myFile
   put URL ( "file:" & myFile ) into myList 
   put "Hello, Let's talk" & return into field "log"
   select before line 1 of  field "input"              // put the cursor at the start of the field
end openCard


3.  To check for specific Sentences
        We want to lookup the whole sentence instead of just 1 word

        Add the following - in red - to the beginning of your getResponse handler:

on getResponse
   put field "input" into theInput                       // save what the user typed
   put theInput & return after field "log"          // put it into the log and go to next line
   put empty into theResponse                      // clear out the response variable
   
   put myList [ theInput ] into theResponse         // see if the sentence (theInput) is in myList
   if theResponse is empty then                         // if theResponse is empty, keep looking...

   repeat for each word w in theInput              // check each word that the user types
      put myList[w] into theResponse               // see if it is in myList
      if theResponse is not empty then            // if a response is returned
         exit repeat                                            // ... then we are done, look no more
      end if
   end repeat
   
   if theResponse is empty then                   // double check if a word/response was found
      if "no" is in theInput  then

    (the rest of your code...)

     else 
         getRandomResponse
      end if
   end if
end if                                                            // add another end-if

Then in your word list - add the sentence and the response:

e.g.
        mother                 Tell me more about your family
        dog                      Tell me more about your pet
        Who are you?      I am me - who are you?

Comments