你好,我制作了一个简单的Alexa技能,要求一个怪物名字并告诉你速度
我询问用户一个怪物名称,然后用户的怪物名称存储在:handlerInput.requestEnvelope.request.intent.slots.name.value
并且我将其保存到变量monster(下面的代码),因此它保存了用户指定的名称。
我还有一个名为typecharts的文件,那里有关于怪物速度的数字。
typecharts文件:
module.exports = {
Werewolf: '60',
Alien: "98",
Herb: "10",
};
so变量monster(下面的代码)正确打印用户给定的名称,问题是这样的:
[我知道如何调用该文件(typecharts)中的数字值,例如Werewolf或Alien,以便alexa可以这样说:。speak(typecharts.Alien ),并显示98,
但是我需要放置一个变量,该变量存储用户给定的monters的名称,以便它查找我们想要的怪物,诸如此类的。speak(typecharts。variable monster here)]所以她会寻找用户说的任何类型的图表,无论是外星人的野狼还是草药。
我尝试通过创建此变量const spe =(typecharts.monster)进行尝试,但是失败了,因为它没有查找用户说的名称(保存在“ monster”变量),它看上去取而代之的是“ monster”,而不是变量中的名称,¿我如何使它查找存储在Monster上的文本?
要修复的代码:
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'CompareIntent';
},
handle(handlerInput) {
const monster = handlerInput.requestEnvelope.request.intent.slots.name.value
const spe = (typecharts.monster) // <- i need to fix this to do what i need.
return handlerInput.responseBuilder
.speak("you said "+ monster +" with speed " + spe ) // <- alexa speech output
.reprompt("tell me more")
.getResponse();
}
handle(handlerInput) {
const monster = handlerInput.requestEnvelope.request.intent.slots.name.value
const spe = (typecharts[monster])
return handlerInput.responseBuilder
.speak("you said "+ monster +" with speed " + spe ) // <- alexa speech output
.reprompt("tell me more")
.getResponse();
}