문제는 quizIntent 핸들러의 루프에서 질문의 배열을 반복 할 수 없다는 것입니다. 첫 번째 질문 만 표시되고 더 이상 이동하지 않습니다. 나머지 코드는 정상적으로 작동합니다. 내가 원하는 것은 배열이 다 떨어질 때까지 계속 질문하고 사용자가 틀린 답을 줄 때 루프에서 빠져 나옵니다.Alexa Intent에서 객체 배열을 반복하는 방법은 무엇입니까?
나는 Alexa Programming의 초보자입니다. 도와주세요. 여기
내 배열 여기const got = [
{
question: "Grey Wind, Lady, Ghost, Shaggydog, Summer and the sixth direwolve's name is?",
answer: 'nymeria',
},
{
question: "What was the name of the sinister castle where Arya and Gendry were held prisoner in season two?",
answer: 'harrenhal',
},
{
question: "What is a person called that can enter the minds of animals?",
answer: 'warg',
},
{
question: "What was the name of the Stark ancestral sword that was melted down by Tywin Lannister?",
answer: 'ice',
}
];
내 알렉사 의도 여기
var handlers = {
"customIntent": function() {
this.response.speak("Would you like to appear for a trial by combat");
this.emit(":responseReady");
},
"quizIntent": function() {
var mydecision = this.event.request.intent.slots.decision.value;
if(mydecision=='no'||mydecision=='nope'||mydecision=='naah'){
this.response.speak("A five year old has more courage than you.");
this.emit(":responseReady");
}
for(var i = 0; i <got.length; i++){
var myanswer = this.event.request.intent.slots.answer.value;
var item = got[i].question;
this.response.speak(item).listen();
if(myanswer!=got[i].answer){
this.response.speak("Wrong Answer. You are dead");
this.emit(':responseReady');
}
if(i==got.length-1){
this.response.speak("You won");
this.emit(':responseReady');
}
}
},
"LaunchRequest": function() {
this.response.speak("Valar Morghulis").listen("You are supposed to say Valar Dohareis");
this.emit(":responseReady");
}
};
인 경우에는 내 의도 스키마 당신이에서 싶어 보면 너무
{
"languageModel": {
"types": [
{
"name": "answerSlot",
"values": [
{
"id": null,
"name": {
"value": "Nymeria",
"synonyms": []
}
},
{
"id": null,
"name": {
"value": "Harrenhal",
"synonyms": []
}
},
{
"id": null,
"name": {
"value": "Warg",
"synonyms": []
}
},
{
"id": null,
"name": {
"value": "Ice",
"synonyms": []
}
}
]
},
{
"name": "decisionSlot",
"values": [
{
"id": null,
"name": {
"value": "Yes",
"synonyms": []
}
},
{
"id": null,
"name": {
"value": "No",
"synonyms": []
}
},
{
"id": null,
"name": {
"value": "Naah",
"synonyms": []
}
},
{
"id": null,
"name": {
"value": "Yeah",
"synonyms": []
}
},
{
"id": null,
"name": {
"value": "Yup",
"synonyms": []
}
},
{
"id": null,
"name": {
"value": "Nope",
"synonyms": []
}
}
]
}
],
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "customIntent",
"samples": [
"Valar Dohareis",
"hello",
"hola"
],
"slots": []
},
{
"name": "quizIntent",
"samples": [
"{decision}",
"The answer is {answer}"
],
"slots": [
{
"name": "decision",
"type": "decisionSlot"
},
{
"name": "answer",
"type": "answerSlot"
}
]
}
],
"invocationName": "quiz game"
}
}
AWS 람다 스킬입니까? – MangoBoy
예. 문제는 람다 함수를 사용하는 것입니다. – thedreamsaver
람다 함수의 시간 초과를 시도하고 늘리십시오. Speaking은 비동기 호출이므로 람다 함수가 시간 초과되었습니다. – MangoBoy