我有一个功能,可以检查游戏是否结束我想要延迟,让用户有时间查看每个答案是否正确,然后再通过屏幕观看游戏。
游戏运行检查在没有超时的情况下运行正常,但是当我设置超时时,我得到函数调用不是函数的错误。
setTimeout(function() {this.CheckGameOver();}, (5 * 1000));
Timeout的设置方式有问题吗?唯一的想法可能是问题,因为该功能完全适用于它自己。
CheckGameOver: function() {
// Check game over clause
var c = this.View.children;
if (this.players[0].answered == 13) { // Check if Player 1 won
// Win the game
gameStopped = true;
isFirstQuestionSetup = true;
if(this.PlayerCount == 1) {
views.get('singlePlayerGame').transitionOut();
clearInterval(this.cpu);
} else {
views.get('twoPlayerGame').transitionOut();
}
views.get('background').switchState(BACKGROUND_STATES.GAME_OVER);
views.get('genericHud').switchState(HUD_STATES.MAIN_MENU);
views.get('gameOver').transitionIn(this.players, this.GameType, this.Language);
}
if (this.playerCount == 1) {
if (this.cpuAnswered == 13) { // Check if CPU won
// Lose the Game (Doh!)
gameStopped = true;
views.get('singlePlayerGame').transitionOut();
clearInterval(this.cpu);
views.get('background').switchState(BACKGROUND_STATES.GAME_OVER);
views.get('genericHud').switchState(HUD_STATES.MAIN_MENU);
views.get('gameOver').transitionIn(this.players, this.GameType, this.Language);
}
} else {
if (this.players[0].answered == 13) { // Check if Player 2 won
// Player 2 Wins
gameStopped = true;
views.get('twoPlayerGame').transitionOut();
views.get('background').switchState(BACKGROUND_STATES.GAME_OVER);
views.get('genericHud').switchState(HUD_STATES.MAIN_MENU);
views.get('gameOver').transitionIn(this.players, this.GameType, this.Language);
}
}
},
答案 0 :(得分:2)
$value = 6;
if (!in_array($value, $option)) {
$query->whereIn('rooms',$option
} else {
$query->whereHas(
'rooms',
function($query) use ($value){
$query->where('rooms', '>=', $value)
});
}
没有引用你的想法。您可以使用es6箭头功能
this
或将setTimeout(() => {this.CheckGameOver();}, (5 * 1000));
绑定到this
setTimeout
答案 1 :(得分:0)
恰好irb(main):001:0> 2.between?(1, 3)
=> true
irb(main):002:0> 3.between?(1, 3)
=> true
irb(main):003:0> 1.between?(1, 3)
=> true
irb(main):004:0> 0.between?(1, 3)
=> false
内的匿名函数与其他内容不同,因此setTimeout
是不同的,并且没有这样的函数。
你应该在this
之外设置类似
setTimeout
和var that = this;
内部调用setTimeout
因此它将解决您的关闭问题。
或者,如果您需要在延迟时间内完成所有操作,请致电CheckGameOver,您可以这样写下您的行:
that.CheckGameOver()