02:09 PM 08/01/2023
well you could do smth likevar start = new Date().getTime(),
score = '0.1';
var interval = window.setInterval(function() {
var time = new Date().getTime() - start;
score = Math.floor(time / 1000);
if(score === 100) {
window.clearInterval(interval);
if(!alert("You win!\nPress 'OK' to play again")){
window.location.reload();
}
}
document.getElementById('displayScore').innerHTML = score += '.00 Score';
});
score = '0.1';
var interval = window.setInterval(function() {
var time = new Date().getTime() - start;
score = Math.floor(time / 1000);
if(score === 100) {
window.clearInterval(interval);
if(!alert("You win!\nPress 'OK' to play again")){
window.location.reload();
}
}
document.getElementById('displayScore').innerHTML = score += '.00 Score';
});
07:17 PM 08/01/2023
Quote from Dasfk , 02:09 PM 08/01/2023Stop copy and pasting stuff from StackOverflow, this isn't a website scripting forum.
well you could do smth likevar start = new Date().getTime(),
score = '0.1';
var interval = window.setInterval(function() {
var time = new Date().getTime() - start;
score = Math.floor(time / 1000);
if(score === 100) {
window.clearInterval(interval);
if(!alert("You win!\nPress 'OK' to play again")){
window.location.reload();
}
}
document.getElementById('displayScore').innerHTML = score += '.00 Score';
});
Besides, there is a way easier way to make this with only 5 lines of code. Let me break it down.
On playerJoin, we set a p.setInterval. Why are we using a p.setInterval? Because when the player is destroyed/left, the p.setInterval automatically clears itself instead of a normal setInterval continuing to run when the player is destroyed. So now, every 60000 miliseconds (1000 miliseconds = 1 second, so 60 seconds), we increase the player's score. Simple as that.
Script: https://gist.github.com/dragonismcode/dfcc1e88d50b9fe03ece3b057bf33a65
Hope this helps!
02:15 AM 19/01/2023
Quote from dargy , 07:17 PM 08/01/2023i mean.. simplifying code is good and all but imo i use stack overflowQuote from Dasfk , 02:09 PM 08/01/2023
well you could do smth likevar start = new Date().getTime(),
score = '0.1';
var interval = window.setInterval(function() {
var time = new Date().getTime() - start;
score = Math.floor(time / 1000);
if(score === 100) {
window.clearInterval(interval);
if(!alert("You win!\nPress 'OK' to play again")){
window.location.reload();
}
}
document.getElementById('displayScore').innerHTML = score += '.00 Score';
});
Stop copy and pasting stuff from StackOverflow, this isn't a website scripting forum.
Besides, there is a way easier way to make this with only 5 lines of code. Let me break it down.
On playerJoin, we set a p.setInterval. Why are we using a p.setInterval? Because when the player is destroyed/left, the p.setInterval automatically clears itself instead of a normal setInterval continuing to run when the player is destroyed. So now, every 60000 miliseconds (1000 miliseconds = 1 second, so 60 seconds), we increase the player's score. Simple as that.
Script: https://gist.github.com/dragonismcode/dfcc1e88d50b9fe03ece3b057bf33a65
Hope this helps!
01:42 PM 20/01/2023
Quote from GottaScooby , 02:15 AM 19/01/2023nothing wrong with copy and pasting code from StackOverflow, just he didn't even think about what type of code he was pastingQuote from dargy , 07:17 PM 08/01/2023Quote from Dasfk , 02:09 PM 08/01/2023
well you could do smth likevar start = new Date().getTime(),
score = '0.1';
var interval = window.setInterval(function() {
var time = new Date().getTime() - start;
score = Math.floor(time / 1000);
if(score === 100) {
window.clearInterval(interval);
if(!alert("You win!\nPress 'OK' to play again")){
window.location.reload();
}
}
document.getElementById('displayScore').innerHTML = score += '.00 Score';
});
Stop copy and pasting stuff from StackOverflow, this isn't a website scripting forum.
Besides, there is a way easier way to make this with only 5 lines of code. Let me break it down.
On playerJoin, we set a p.setInterval. Why are we using a p.setInterval? Because when the player is destroyed/left, the p.setInterval automatically clears itself instead of a normal setInterval continuing to run when the player is destroyed. So now, every 60000 miliseconds (1000 miliseconds = 1 second, so 60 seconds), we increase the player's score. Simple as that.
Script: https://gist.github.com/dragonismcode/dfcc1e88d50b9fe03ece3b057bf33a65
Hope this helps!
i mean.. simplifying code is good and all but imo i use stack overflow