创建“伪造的AI".聊天程序 [英] Creating a "fake AI" chat program

查看:97
本文介绍了创建“伪造的AI".聊天程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我一直在创建一个聊天机器人(用于娱乐和练习).

Hey everyone, I've been creating a little chat bot (for fun and practice).

我有以下功能无法正常使用(此处为完整代码):

I have the following function which isn't working correctly (FULL CODE HERE):

function runAI() {
            if (i.val().length > 0) { 
                if ($.inArray(i.val(), helloInputArray)) {
                    r = Math.floor(Math.random()*4);                        
                    o.html(o.html()+helloOutputArray[r]);
                    i.val('');
                    i.focus();
                } else if ($.inArray(i.val(), byeInputArray)) {
                    r = Math.floor(Math.random()*4);                        
                    o.html(o.html()+byeOutputArray[r]);
                    i.val('');
                    i.focus();
                } else {
                    o.html(o.html()+"I don't know what that means...<br />");
                    i.val('');
                    i.focus();
                }
            }
        }

似乎总是返回helloOutputArray ...

It always seems to return the helloOutputArray...

推荐答案

$.inArray不返回true或false,它返回从0开始的索引.

$.inArray does not return true or false, it returns a 0 based index.

-1表示未找到,> -1是数组中匹配项的索引:

-1 means not found, > -1 is the index of the match in the array:

if ($.inArray(i.val(), helloInputArray) > -1) {
    // The item was in this array
}

此处的工作版本.

这篇关于创建“伪造的AI".聊天程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆