我做了一个简单的问答游戏。这是我在一个对象中拥有的一些相关方法。
但不起作用。我总是在“rightAnswerGot”函数中遇到错误。控制台为 this.addVariantsHtml(this.updateCharacter()) 删除“未捕获的类型错误未定义不是对象方法的函数”;
BasicGame.Game.prototype = {
actionOnClick: function (button) {
var log;
if(button.value==this.char_bubble.text) {
setTimeout(this.rightAnswerGot,1000);
} else {
// wrong
swoshsound.play();
}
console.log(log);
},
rightAnswerGot: function (){
this.addVariantsHtml(this.updateCharacter());
},
addVariantsHtml: function(id) {
this.answer = this.getAnswersVariants(id);
for (var i = 0; i < 6; i++) {
this.button[i].value = this.answer[i]['trans'];
this.button[i].char_id = this.answer[i]['id'];
this.ans_text[i].setText(this.answer[i]['trans']);
}
},
updateCharacter: function() {
var i = this.getRandomCharacter();
console.log("updateCharacter: "+i + " " +this.chars[i]);
this.char_bubble.setText(this.chars[i].getPath());
return i;
}
}
目的是在用户选择正确答案时冻结游戏一秒钟,然后转到下一个问题。任何想法为什么会发生?
谢谢