Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Javascript - No longer working

  1. #1
    Join Date
    Feb 2011
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Javascript - No longer working

    I've been using the following in a pattern matching chatbot. A person types in an input box and the chatbot responds in an output box.

    If someone types "yes" the bot responds with the following except on message 4 where I ask a question. Once that question is asked it will no longer trigger which is what I want. I don't want that question to be asked over and over. This all worked until recently. I can't figure out why it no longer works. Thanks!





    Code:
    var yes_q4_asked="false";
    
    if (input.search("yes")!= -1) {  
    message[0] = "ok, yes it is."; 
    message[1] = "yes, I suppose so."; 
    message[2] = "ok, I understand."; 
    message[3] = "ok, I guess so."; 
    message[4] = "yeah, I reckon so. Say what color are your eyes?"; 
    message[5] = "yes, I thought as much."; 
    num = [Math.floor(Math.random()*6)]
    if ((num==4) && (yes_q4_asked=="false"))
    { 
      yes_q4_asked=="true";
      document.result.result.value = message[num];
      return true;
    }
    while (num==4)
    {
      num = [Math.floor(Math.random()*6)]
    }
    document.result.result.value = message[num]; 
    return true;}

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    What is the purpose of this project? In order to give you the best answer possible, I think it would make sense to figure out your goals, and whether this approach (in general) is the best.

    I can imagine a few reasons:
    1. You want to learn Javascript. (If that's the case, then we should solve the immediate problem.)
    2. You want to create a functional, useful AI chat (which is very hard, and this is probably not the way to do it).
    3. You're doing this as some kind of test for another project (if so, what?).
    4. This is for some kind of school assignment (if so, what? And keep in mind we don't do homework for you here).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2011
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    I can imagine a few reasons:

    Such as?

    1. You want to learn Javascript. (If that's the case, then we should solve the immediate problem.)

    I want to solve this problem


    2. You want to create a functional, useful AI chat (which is very hard, and this is probably not the way to do it).

    I already have a functioning Chatbot.

    3. You're doing this as some kind of test for another project (if so, what?).

    This is 1 part of the chatbot in question.


    4. This is for some kind of school assignment (if so, what? And keep in mind we don't do homework for you here).

    I'm 52 years old. I graduated a long time ago

  4. The Following User Says Thank You to chriscc17 For This Useful Post:

    bernie1227 (04-23-2013)

  5. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    1. You want to learn Javascript. (If that's the case, then we should solve the immediate problem.)

    I want to solve this problem
    Ok, but do you want to solve this problem to fix the code because you want this particular code to work, or do you want to accomplish some larger goal? Is this educational for you to learn JS, or is this for you to make it work again? (These different goals could have different answers.)

    2. You want to create a functional, useful AI chat (which is very hard, and this is probably not the way to do it).

    I already have a functioning Chatbot.
    Hm. What does it accomplish? Is this the whole code, or does this integrate into something larger?
    The three models of chatbot I can think of are the following:
    1) Purely rule based-- if X then Y (similar to what you have here). If that's what you're working with, why is this an exception?
    And this is really the only kind that is possible to create with a "perfect" result-- if you have certain expected kinds of input, you can make something that works well; further variation beyond this is more challenging.
    2) Statistical, using guesses about what appears in the input and what might be a good reply. These can work (an example is "SmarterChild", a bot from AOL(?) on AIM), but they're far from perfect and don't do well with odd input. Your current system doesn't look anything like this, so that's why I asked.
    3) A true grammatical model that processes language fully-- at the moment, that's basically just in science fiction. People are working on it, but the best models are statistical and just a means to an end rather than anything meant to really capture linguistic structure or be reliable in all domains.


    Generally speaking, it's possible to create a reliable chatbot if you can limit the domain and vocabulary. Beyond that, you'll probably run into trouble. (We've all had the frustrating experience of talking to a robot on the phone and trying to get it to do something it isn't programmed to do, or not in the expected order.)


    (For the record, I'm a Linguistics grad student, and I have some (limited) experience with this kind of thing, more observing what's out there than making it myself.)

    3. You're doing this as some kind of test for another project (if so, what?).

    This is 1 part of the chatbot in question.
    It's up to you, but I'm confused why this would be a separate component. Wouldn't this be just one of many similar sections of code?

    4. This is for some kind of school assignment (if so, what? And keep in mind we don't do homework for you here).

    I'm 52 years old. I graduated a long time ago
    I'm not questioning your motives, but we do get "homework questions" here fairly often and I just wanted to explain that.



    In short, it would help to know the context.
    ---

    Anyway, focusing on the code itself, it's a little hard to tell what's going on. Is this part of some larger loop? Otherwise I don't see how this repeats at all.

    Your current while loop doesn't make very much sense to me. It will only run if you already have num==4, meaning you've already asked that. I'd imagine you want to remove that while loop entirely. Then use an if statement to display the result as long as #4 hasn't already been asked. Something like this--
    Code:
    var yes_q4_asked="false";
    
    if (input.search("yes")!= -1) {  
    message[0] = "ok, yes it is."; 
    message[1] = "yes, I suppose so."; 
    message[2] = "ok, I understand."; 
    message[3] = "ok, I guess so."; 
    message[4] = "yeah, I reckon so. Say what color are your eyes?"; 
    message[5] = "yes, I thought as much."; 
    num = [Math.floor(Math.random()*6)]
    if (yes_q4_asked=="false")
    {
       if (num==4)
       { 
          yes_q4_asked=="true";
       }
       document.result.result.value = message[num];
       return true;
    }
    else
    {
       return false;
    }
    }
    Finally, you may have some trouble with variable scope here; it looks like you're creating a local variable, which should not be available on the next iteration-- yes_q4_asked will be re-created every time you call this function (I'm assuming this is in a function-- that's why it's hard to help without more code and context).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #5
    Join Date
    Feb 2011
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    I've been doing chatbots for 13 years now. This bot is one of the best. It's proven it's worth in numerous contest. Having a good bot doesn't make me a good programmer though. Good bots are more about what they say than the programming behind them. So I'm not looking for a major rewrite or a different approach to building a bot. I just want to get this part working again. As I said it worked fine for many years. The actual bot is huge but here is a small demo that I use for testing. In short, if it works in the demo it will work in the main bot. Maybe that will help people see what the bot is.

    http://www.daniellechuchran.com/aademo.html

    In short if you type in "yes" it is going to reply with what you see in the example. However if message 4 is triggered I don't want it to trigger again. Only once...no more. How can I do that. I want the other "yes" replies to continue as is but I obviously don't want to keep asking the same question of "what color are your eyes" over and over.

    Note: I didn't mention the main bot or a link for fear people might perceive this as some advertising ploy.

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    Note: I didn't mention the main bot or a link for fear people might perceive this as some advertising ploy.
    We do have pretty strict rules about spam, but you're welcome to post a link if it's related to your question, because that's important in helping us answer it.

    I've been doing chatbots for 13 years now. This bot is one of the best. It's proven it's worth in numerous contest. Having a good bot doesn't make me a good programmer though. Good bots are more about what they say than the programming behind them. So I'm not looking for a major rewrite or a different approach to building a bot. I just want to get this part working again. As I said it worked fine for many years. The actual bot is huge but here is a small demo that I use for testing. In short, if it works in the demo it will work in the main bot. Maybe that will help people see what the bot is.
    Interesting. So your purpose is more about making this clever and interesting, rather than thinking about linguistic structure or models of language? That's one option (and it sounds like what I said above as option #1 for making a bot), and it does work-- it just requires a lot of definitions in your code to respond to lots of kinds of input. I don't mean to criticize you at all with my comments; I'm just trying to understand what you're after.


    There are more efficient ways to write this, probably. But if you're happy with it, that's fine.

    As for the specific issue, did you try to use the code I showed you above?

    The trouble, I think, is going to be variable scope. When you define a variable within a function, it only exists within that function (and only in that instance of the function). To get around this, you'll need a global variable so that you can track it from iteration to iteration. You can do that by moving this line outside of the function:
    var yes_q4_asked="false";
    Does that make sense?


    Unfortunately I'm much better with PHP than Javascript, so I don't know if I can give you the specific answer to debug this code, but I wanted to reply because I'm interested in the subject matter.

    Have you considered using a database? That might make things simpler. But that would be for a new project, rather than changing this one if it's mostly working.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #7
    Join Date
    Feb 2011
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    Yes, I'm a part of the Chatterbox Challenge which is an annual chatbot contest. We started it in 2001 so this will be the 13 year now. It's not really a scientific contest as we all know the limits of AI. It's more of a place where people can show off their work. Virtually every bot of note including Smarter Child has entered it at some point.

    Yes, as you can imagine the bot has hundreds of variables. They are all located outside the function. I still don't get why it stopped working.

    Unfortunately I'm much better with PHP than Javascript, so I don't know
    Okay, thanks for the help. I'll try to run across some javascript expert and see if I can get to the bottom of things.

  9. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    They are all located outside the function.
    Ok, that's important. Assuming there's nothing wrong there, then--

    Have you tried my code above, or something like it? Does that seem to do what you want? (I haven't tested it, because I don't have a context to test it in), but I think that might work.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #9
    Join Date
    Feb 2011
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    No, it doesn't work for me as written.

    (I haven't tested it, because I don't have a context to test it in),
    I made available here a small demo bot for testing. It super small so it's easy to use without having to wade through some lengthy script

    http://www.daniellechuchran.com/aademo.html

  11. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    260
    Thanked 690 Times in 678 Posts

    Default

    So let me make sure I know what you're asking:
    1. You want the bot to continuously respond to "yes" with one of those options, never stopping.
    2. You want #4 to show up randomly, but only show up once.
    3. After that, it should keep replying, with the other options, but just not #4 again.

    Is that right? My other code was a misinterpretation, I think-- it was designed to have the bot stop replying entirely after #4 was asked once. But you just want to stop #4.


    In that case, I think there's a simple typo, now that I see how all of this works. You have a == instead of =:
    yes_q4_asked=="true"; (line 50)
    Change that to:
    yes_q4_asked="true";


    Sometimes it's the little things. If that works, great! And sorry for apparently turning a simple answer into a complicated one, but it was hard to figure out without context.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Similar Threads

  1. no longer accessible
    By auntnini in forum The lounge
    Replies: 18
    Last Post: 08-26-2012, 01:46 AM
  2. Login no longer works
    By ChroniX in forum PHP
    Replies: 2
    Last Post: 06-12-2010, 12:26 PM
  3. javascript code not working in ie but working in firefox
    By sukanya.paul in forum JavaScript
    Replies: 2
    Last Post: 02-20-2009, 12:44 PM
  4. Anylinks no longer working in IE6
    By kealaz in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 05-25-2008, 06:26 AM
  5. longer cookies
    By DisturbedRoach in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 09-10-2004, 09:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •