How do i make my timer reset when you lose the game? here is a link to the game: https://editor.p5js.org/TobiasR/sketches/dvbIsv7Ah
Im new to programming and just recently started making my own game so any advice on how to make it better is appreciated.
You have used system second in your code instead of that you can use the below code for creating a timer in your application.
let hr = 0, min = 0, sec = 0;
let intervalId = setInterval(() => {
sec++;
if(sec === 60) {
min++;
sec = 0;
if(min === 60) {
hr++;
min = 0;
}
}
console.log(`${hr}: ${min}: ${sec}`);
}, 1000);
Note: Don't forget to clearInterval(intervalId) when user lose the game. For using intervalId in other functions you have to declare it globally.