Hi,
I don’t know what I’m doing wrong here but if I set bool value to either true or false my if statement (this.increment) does not execute accordingly.
This is my code:
var Coins = pc.createScript('coins');
Coins.attributes.add('coins', {type: 'entity'});
Coins.prototype.initialize = function()
{
this.coins.element.text = globals.coins;
this.buffering = false;
this.increment = false;
this.coinBuffer = 0;
this.value = 0;
this.app.on('coin', function (buffering, increment, value)
{
this.buffering = buffering;
this.increment = increment;
this.coinBuffer = (increment === true) ? globals.coins + value : globals.coins - value;
}, this);
};
Coins.prototype.update = function(dt)
{
if(this.buffering)
{
console.log('buffering');
this.value = dt * 1000;
if(this.increment === true)
{
console.log('true');
globals.coins += this.value;
if(globals.coins > this.coinBuffer)
{
globals.coins = this.coinBuffer;
this.buffering = false;
}
}
else if(this.increment === false)
{
console.log('false');
globals.coins -= this.value;
if(globals.coins < this.coinBuffer)
{
globals.coins = this.coinBuffer;
this.buffering = false;
}
}
this.coins.element.text = Math.round(globals.coins);
}
};
So, if I do:
this.app.fire('coin', true, true, 900);
I don’t get the console.log(‘true’) or console.log(‘false’) output, but I do get the console.log(‘buffering’) ouput. What is happening here?