我似乎无法弄清楚为什么这个if()语句有效,任何想法为什么?
Game.Items = {autoClickers: [50, 1, "Gives you one click every second, cost 50 clicks."]};
Game.UsersItems = {itemAutoClickers: [0], itemClickingTeam: [0]};
if(Game.UsersItems.itemAutoClickers > 0) {
setInterval(function() {
Game.Clicks = Game.Clicks + Game.Items.autoClickers[1];
getElement('clicks').innerText = "Clicks: "+Game.Clicks;
document.title = "Pointer Clicker | Clicks: "+Game.Clicks;
}, 1000);
}
答案 0 :(得分:2)
Game.UserItems.itemAutoClickers是一个数组,它是你要检查的.length
吗?
或者它是数组第一个索引的值?
在这种情况下 Game.UserItems.itemAutoClickers[0]
答案 1 :(得分:2)
您是否尝试检查itemAutoClickers
数组中的项目数是否大于0,或者第一项的值是否大于0?
Game.UsersItems.itemAutoClickers.length > 0
或
Game.UsersItems.itemAutoClickers[0] > 0