I'd change it to use setTimeout
. So:
var increment = setInterval(increment,1000); // gain 1 ever second // THIS IS WHAT I WANT TO CHANGE
function increment(){
Coal = Coal % 99999999999999999999 + CoalRate;
totalCoal = totalCoal % 99999999999999999999 + CoalRate;
document.getElementById("Coalcounter").innerHTML="Coal : " + Math.round(Coal);
document.getElementById("CoalClickercost").innerHTML="Upgrade Coal Clicker : " + Math.round(CoalClickerPrice);
document.getElementById("CoalRatecost").innerHTML="Upgrade Coal Rate : " + Math.round(CoalRatePrice);
}
Would become:
var interval = 1000
function increment(){
Coal = Coal % 99999999999999999999 + CoalRate;
totalCoal = totalCoal % 99999999999999999999 + CoalRate;
document.getElementById("Coalcounter").innerHTML="Coal : " + Math.round(Coal);
document.getElementById("CoalClickercost").innerHTML="Upgrade Coal Clicker : " + Math.round(CoalClickerPrice);
document.getElementById("CoalRatecost").innerHTML="Upgrade Coal Rate : " + Math.round(CoalRatePrice);
window.setTimeout(interval)
}
increment()
Then your onclick becomes as simple as something like..
<button onclick="swapInterval">Swap</button>
and
function swapInterval() {
if(interval==1000) interval = 2000
else interval = 1000
}
Note that this won't change it for the current loop (e.g. if you're on 2000, you push the button after 500ms, you'll still need to wait another 1500ms before it triggers).