DirectEntry 和基础 Python 聊天 AI:Panda3D

我有以下两个脚本。

脚本 1:

while True:userInput = raw_input(">>> ")if userInput.lower() in ["yo",'hi', 'hello', 'hi there', 'hey there']:    print "Hi, I'm Jane."elif userInput.lower() in ["sup", "what's up", "how are you", "how are u", "sup?", "what's up?", "how are you?", "how are u?"]:    whassup = ['Not much, you?','The usual!', 'Working on paperwork.', 'Helping out, haha.', 'Annoying my sisters.']    print(random.choice(whassup))        elif userInput.lower() in ["cool", "awesome", "sounds cool", "rad"]:    print "Aww, thanks!"else:    print "Sorry, I can only use SpeedChat."

然后,这是脚本 2,它是来自这里的示例代码的稍作修改版本:

    #添加一些文本bk_text = "This is my Demo"userin = OnscreenText(text = bk_text, pos = (0, 0.7), scale = 0.07,fg=(0,0,0,1),align=TextNode.ACenter,mayChange=1)userin.setFont(font)#回调函数设置文本 def setText(textEntered):    userin.setText(textEntered)#清除文本def clearText():    b.enterText('')#添加按钮b = DirectEntry(text = "" ,scale=.05, command=setText,initialText="Type Something", numLines = 2,focus=1,focusInCommand=clearText)

所以,像这样。我想要做的就是让用户在 DirectEntry 框中输入他们的输入,然后 Panda3D 面板(有一个动画角色,但这并不相关)会打印出程序的响应。

例如,用户输入“Hello!”,然后程序会继续在屏幕上输出“Hi, I’m Jane.”

我对编程非常新手,我做的一切都超级复杂;稍微解释一下会非常有帮助!!谢谢你一万次!


回答:

实际上,我在尝试一个解决方案时发现它确实可以工作!我只是因为不会打字而全部打错了:P

如果有人好奇的话,这里是整个脚本:

#添加一些文本bk_text = "Hi, I'm Jane."userin = OnscreenText(text = bk_text, pos = (0, 0.7), scale = 0.07,fg=(0,0,0,1),align=TextNode.ACenter,mayChange=1)userin.setFont(font)#回调函数设置文本 def setText(textEntered):        if textEntered.lower() in ["yo",'hi', 'hello', 'hi there', 'hey there']:                txt = "Hello!"                grunt.play()        elif textEntered.lower() in ["sup", "what's up", "how are you", "how are u", "sup?", "what's up?", "how are you?", "how are u?"]:                whassup = ['Not much, you?',"The sky's up.", 'Working on paperwork.', 'Researching cookie recipes.', 'Being a giant robot bird, as usual.']                txt = (random.choice(whassup))                statement.play()        elif textEntered.lower() in ["cool", "awesome", "sounds cool", "rad"]:                txt = "Haha, thanks."                statement.play()        elif textEntered.lower() in ["when i was a young boy"]:                txt = "MY FATHER, TOOK ME INTO THE CITY, TO SEE A MARCHING BAND!"                grunt.play()        elif textEntered.lower() in ["jane", "hey jane", "jane?", "hey jane?"]:                txt = "Yes?"                murmur.play()        elif textEntered.lower() in ["who is it", "who is it?", "it is", "is it", "john cena"]:                txt = "JOHN CENA"                JC.play()        else:                txt = "I don't speak Toon?"                question.play()    userin.setText(txt)#清除文本def clearText():    b.enterText('')#添加按钮b = DirectEntry(text = "" ,scale=.05, command=setText,initialText="Type Something", numLines = 2,focus=1,focusInCommand=clearText)b.setPos(-0.27, 0, -0.6)

所以!如果有人好奇,尽管使用它。我可能会用某种 PyAIML 替换 if/elif/else 部分,但对于一个简单的游戏来说,这绝对是棒极了!:)

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注