How can I save "back" a variable in a JS parameter function like this:
var warehouseCapacity = 100;
var wood = 0,
wood_production = 1;
function onLoad() {
setInterval(outCalc(), 1000);
}
function outCalc() {
calc(wood, wood_production, "wood_paragraph");
}
function calc(materialVar, productionVar, Id) {
if (materialVar < warehouseCapacity) {
if ((warehouseCapacity - materialVar) < productionVar) {
document.getElementById(Id).innerHTML = warehouseCapacity;
}
else {
materialVar += productionVar;
document.getElementById(Id).innerHTML = materialVar;
}
}
else{
//The warehouse is full so it can't hold any more materials.
}
}
It only writes out ones because it doesn't set back the imported "materialVar". It imports in the value of the "materialVar". If I have written this without parameters it would work perfectly.
Ask if anything is not clear please.
Sorry for my mistakes, but I am not a native speaker.