User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'move')' in this line: 'moneyArray[a].move();' Line Number: 27
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'move')' in this line: 'moneyArray[a].move();' Line Number: 27
Initial prompt
Money Clicker
var Money = Container.expand(function () {
var self = Container.call(this);
var moneyGraphics = self.createAsset('money', 'Money Graphics', .5, .5);
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
var moneyArray = [];
var score = 0;
var isGameOver = false;
var tickOffset = 0;
LK.on('tick', function () {
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
for (var a = moneyArray.length; a >= 0; a--) {
moneyArray[a].move();
if (moneyArray[a].y > 2732) {
moneyArray[a].destroy();
moneyArray.splice(a, 1);
}
}
if (tickOffset++ % 30 == 0) {
var newMoney = new Money();
newMoney.x = Math.random() * 2048;
newMoney.y = 0;
moneyArray.push(newMoney);
self.addChild(newMoney);
}
});
stage.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
for (var a = moneyArray.length; a >= 0; a--) {
if (moneyArray[a].intersects(pos)) {
moneyArray[a].destroy();
moneyArray.splice(a, 1);
score++;
scoreTxt.setText(score);
}
}
});
});