17 Replies Latest reply on Nov 28, 2007 11:50 AM by Greg Dove

    Chat Bot not reading my text...

    kovacic
      The code below is attached to the submit button.. It is supposed to look for certain words in the text, and respond accordingly. But when I type in the word, like mike, it wont reply accordingly. can anyone tell if I am missing something or if my syntax is off?

      Thanks in advance!
        • 1. Re: Chat Bot not reading my text...
          kovacic Level 1
          I thought this would be an easy one. :\
          • 2. Re: Chat Bot not reading my text...
            Greg Dove Level 4
            It might be.... It's just that its been so long since I used an

            on () style clipHandler that I can't remember what scope it runs in.

            Its probably better to put in on the timeline... but for now all I can think of is to try this:


            myTimer = setInterval(this,"respond", i);

            • 3. Chat Bot not reading my text...
              Greg Dove Level 4
              Forgot to say: put a trace in your respond function to see if its actually being called.

              If its not, try declaring the respond function as timeline code.

              • 4. Re: Chat Bot not reading my text...
                kovacic Level 1
                I think the issue actually lies in the following code:

                if (_root.user.text.indexOf("mike")!=-1) {
                _root.reply.htmltext = _root.reply.htmltext = "<b>Santa Clause: </b>string was found";
                _root.status.text = "";
                } else {
                _root.reply.htmltext = _root.reply.htmltext = "<b>Santa Clause: </b>string was not found";
                _root.status.text = "";
                }



                because it seems to be the IF THEN statement thats not catching on... Here is the specific line.

                if (_root.user.text.indexOf("mike")!=-1) {

                Let me know what you think..
                • 5. Re: Chat Bot not reading my text...
                  Greg Dove Level 4
                  Couple of things

                  this is not what you intended:
                  _root.reply.htmltext = _root.reply.htmltext = "<b>Santa Clause: </b>string was found";

                  You intended this:
                  _root.reply.htmltext = _root.reply.htmltext +"<b>Santa Clause: </b>string was found";

                  But I don't know how you'll get on appending to htmlText... it might work. Might not.

                  Are you sure the setInterval is correctly targeting the respond function.
                  Put a trace action after:

                  function respond() {
                  trace('responding');


                  after:

                  if (_root.user.text.indexOf("mike")!=-1) {
                  trace('found mike');

                  and

                  } else {
                  trace("mike's not home');



                  Let me know if you see
                  'responding' trace out and then you get a mike's not home message.




                  • 6. Re: Chat Bot not reading my text...
                    kovacic Level 1
                    Its saying mike's not home, even when I type in mike under the user textbox..

                    I have a feeling it is my syntax on the line:

                    if (_root.user.text.indexOf("mike")!=-1) {

                    because even when mike is typed in, it returns false.
                    • 7. Re: Chat Bot not reading my text...
                      Greg Dove Level 4

                      Ok, then the path to the user textfield might be wrong perhaps because that looks OK to me.

                      function respond() {
                      trace(_root.user.text)

                      does that trace undefined or does it show your text
                      • 8. Re: Chat Bot not reading my text...
                        Greg Dove Level 4
                        I was assuming your textfield is called 'user'. If user is a containing clip and your text field is called 'text' then you need (_root.user.text.text.indexOf(
                        • 9. Re: Chat Bot not reading my text...
                          kovacic Level 1
                          I placed this in the button:
                          if (_root.user.text=="mike") {
                          trace('True');
                          }else{
                          trace('False.');
                          }

                          and when i type in :

                          mike

                          in the field, it returns true. I did check the field name just in case though..
                          This is mind boggling.. I can send you the fla if it helps.
                          • 10. Re: Chat Bot not reading my text...
                            kovacic Level 1
                            Wow... now im REALLY confused... this little chunk of code DOES work :P

                            // TRACE STUFF
                            if (_root.user.text.indexOf("mike")!=-1) {
                            trace('TRUE');
                            }else{
                            trace('FALSE');
                            }
                            • 11. Re: Chat Bot not reading my text...
                              Greg Dove Level 4
                              Put your fla up somewhere and post a message with a link here to download it.
                              I (or others here) will be able to fix it and let you know what was wrong.

                              • 12. Re: Chat Bot not reading my text...
                                kovacic Level 1
                                I put the FLA here:
                                http://cid-96130dac976eef2f.skydrive.live.com/self.aspx/Public

                                just go into the public folder...

                                I found that if I comment out the code that handles the chat delay, and the 'santa is typing...' message, it makes the script works..

                                Also, in the code, where it looks to see if a certain word exists in the sentance
                                LINE:
                                if (_root.user.text.indexOf("mike")!=-1) {

                                It does not work when I use those OR functions as shown below:
                                if (_root.user.text.indexOf("mike" || "Dave" || "Pete")!=-1) {

                                It ignores everything except the last entry, in this instance, Pete.

                                This seems like it should be simple, but for some strange reason, its not working.

                                • 13. Chat Bot not reading my text...
                                  Greg Dove Level 4
                                  Hi, I just took a look at it.

                                  Two things:
                                  1.
                                  You have the following on frame 11:
                                  user.text="";
                                  If you comment out that line, it will work. (your setInterval code is running after user.text has been set to "" so mike is no longer there.
                                  A better solution might be as per the attached code. Doing it this way, you can leave that code on frame 11 untouched.


                                  2. the correct way to test multiple string matches is to test each string separately. An example in the code also.

                                  • 14. Re: Chat Bot not reading my text...
                                    kovacic Level 1
                                    Hey! That works!!! you RULE!

                                    Also, I added this to the bottom:
                                    _root.reply.scroll = _root.reply.scroll * 2;

                                    and fixed the scrollbar association to the reply screen to make sure it scrolls properly.

                                    In the future, I am going to give myself more time and avoid projects that are out of my league . :)

                                    Thanks!!!
                                    • 15. Re: Chat Bot not reading my text...
                                      Greg Dove Level 4
                                      No problems. You don't need to avoid things you can't do it yourself yet (with time you will be able to do it)... you can always subcontract some parts out (but you need to allow some extra time to manage that).
                                      • 16. Re: Chat Bot not reading my text...
                                        kovacic Level 1
                                        True... May I ask one more quick question?

                                        I am trying to make the text field lower case only... either that, or have whatever they type, convert to lower case automatically before it goes through the script.. I have found much code to do this, but none has worked for me... Here is one that I tried:


                                        _root.result = _root.original.toUpperCase();

                                        but to lower of course.
                                        • 17. Re: Chat Bot not reading my text...
                                          Greg Dove Level 4

                                          all you need change in that code above is this:

                                          _root.user.saveText=_root.user.text.toLowerCase();

                                          then your check for "mike" will get "Mike" and "mIKe" as well.