Variables declared in initialize function return errors later saying they are not defined

Every time I try declaring a variable in the default initialize function and try accessing it in another function later it says the variable is not defined.
For example:

// initialize code called once per entity
CheckRoll.prototype.initialize = function() 
{
    var results = [1,2,3,4,5,6];
    var bestCount = 0;
    var bestValue = null;
    var secondCount = 0;
    var secondValue = null;
    var currentCount = 0;
    var currentValue = null;
    var diceValue = 0;
    
    var dice = this.app.root.findByTag('Dice');
    
    this.stopped = false;
    this.timer = 0;
};

This code returns an error saying diceValue is not defined when I try to access it later.
Full Code: https://playcanvas.com/editor/code/529780?tabs=10861152

This is because in JavaScript, local variables are released after the function called. If you want to access a variable in somewhere, you should make it as a instance property. Like:

CheckRoll.prototype.initialize = function() {
    var dice = this.app.root.findByTag('Dice');
    
    this.stopped = false;
    this.timer = 0;
    this.diceValue = 0;
};

So you can access this.diceValue in other methods of CheckRoll.

Yup, that did it. Seems like everything is all about this..