2019-04-11 20:16:33 (edited by redfox 2019-04-11 20:17:07)

I don't mean the set timers like for making functions appear after a certain amount of time, I mean like bgt's timers. Here, I'll give you an example:

timer movetimer;
int movetime=500;
void main()
{
if(key_down(KEY_SPACE) and movetimer.elapsed>=movetime)
{
//play a sound.
}
}

I want to be able to do that, with the arrows though.

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-04-11 20:35:18

I guess you could use setinterval to either do this directly, or you could create a class, then use set interval and set one function that updates every timer every 50 secs or so.
That might not be the best idea though.

2019-04-11 20:43:19

You know that timers are just a wrapper class which stores the time when the timer starts (e.g. when calling restart()) and elapsed just returns the current time minus the start time of the timer. Pausing works by storing the already elapsed time and adding it to the elapsed time in the end. Thats easily reproducable in any language which can retrieve the current time in at least seconds, if not milliseconds, like using a UNIX timestamp.
Best Regards.
Hijacker

2019-04-11 21:04:32

I am vary vary unfamiliar with javascript.
Could you give me an example?

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-04-11 21:47:52

read this:
https://www.w3schools.com/jsref/jsref_gettime.asp

also just google time and javascript and learn about unix time.

here is essentially what you want to do. not sure if everything is super optimal here. probably better way of doing it. read up on date and time in javascript. just look at w3c schools for pretty much all you need.

// create a "timer"
let timer1 = new Date();

//set listener for when key is pressed
window.onkeypress = function () {
let currentTime = (new Date()).getTime();
if( timer1.getTime() - currentTime > 500){
//do something
}
};