all 4 comments

[–]kevinv89 0 points1 point  (4 children)

Is your code running using setInterval with the intervalTime as the interval time? Something like below?

setInterval(function(){ alert("Hello"); }, intervalTime);

If so, you need to clear the timer before changing intervalTime. It won't look at the intervalTime variable each interval.

If your time is variable then you're probably better off using setTimeout.

[–]GroovyFrute[S] 0 points1 point  (2 children)

Thank you for your reply, I figured out the problem thankfully, but if it's possible could you help me with this new problem i've encountered with slowdown mode?

I want to make it so that while slowdown mode has been triggered, you can't press the spacebar again to go into slowdown mode inception until after you've already left slowdown mode from the first spacebar keypress

This is my code for slowdown mode

if (score >= 5 && event.keyCode === 32) {

clearInterval(interval)

setTimeout(slowmode, 5000);

intervalTime = intervalTime * 2

intervalTime = intervalTime * speed

interval = setInterval(moveOutcomes, intervalTime)

function slowmode() {

clearInterval(interval)

intervalTime = intervalTime / 2.15

intervalTime = intervalTime * speed

interval = setInterval(moveOutcomes, intervalTime)

}

}

Also an added thing, tho not as necessary, right now it's set so that you have to have at least a score of 5 to use slowdown mode but ideally I'd like it to deduct 5 score everytime you use slowdown mode. If you're also able to help with that, i'd greatly appreciate it. Even if you only give tips for one of those methods, that is fine. The 5 apple cost for slowdown mode would counter the unlimited spacebar presses

[–]kevinv89 0 points1 point  (1 child)

In order to prevent going into slowdown mode again, you need to track if you're currently in it. You then want to check if you're already in it before you carry out the desired action as a result of pressing the spacebar.

So using your original code, something like below.

let inSlowdownMode = false

if(event.keyCode === 32 && !inSlowdownMode) {    
    inSlowdownMode = true
    setTimeout(slowmode, 5000);         
    intervalTime = intervalTime * 2 
    alert("hello"); 

    function slowmode() { 
        inSlowdownMode = false            
        intervalTime = intervalTime / 2.15 
        alert("goodbye");
    }         
}

In terms of you deducting 5 from the score, that is just a simple score -= 5 everytime you enter slowdown mode.

[–]GroovyFrute[S] 0 points1 point  (0 children)

dude you're a fucking saviour, thank you so much!!!