我正在使用VueJS制作足够简单的资源管理游戏/界面。目前,我希望roll
每12.5秒激活一次该功能,并将结果用于其他功能。目前,尽管我不断收到以下错误:
未捕获的TypeError:无法读取未定义的属性“ roll”(...)
我试过了:
app.methods.roll(6);
app.methods.roll.roll(6);
roll.roll()
roll()
但似乎无法访问该功能。任何人有任何想法我将如何实现?
methods: {
// Push responses to inbox.
say: function say(responseText) {
console.log(responseText);
var pushText = responseText;
this.inbox.push({ text: pushText });
},
// Roll for events
roll: function roll(upper) {
var randomNumber = Math.floor(Math.random() * 6 * upper) + 1;
console.log(randomNumber);
return randomNumber;
},
// Initiates passage of time and rolls counters every 5 time units.
count: function count() {
function counting() {
app.town.date += 1;
app.gameState.roll += 0.2;
if (app.gameState.roll === 1) {
var result = app.methods.roll(6);
app.gameState.roll === 0;
return result;
}
}
setInterval(counting, 2500);
...
// Activates the roll at times.
}
}