I have a number in a object value that I want to dynamically update as the code runs. So for example, if the value of the number is 30, when I run my code, I want to be able to update this number to say.. 20 without me actually having to go into the code and personally update it to 20.
How can I write code that will update this object value? The trouble I'm having is with a timer system that keeps registering the value of 30 every 1 second instead of the NEW value assigned to it after subtracting some numbers.
var count = character.energy; // My Energy level is 30
var counter = setInterval(timer, 1000);
function timer() {
count += characterstats.energyregen;
if (count >= 30){
clearInterval(counter);
}
document.getElementById("energy").innerHTML = count;
character.energy = count;
}