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.

yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

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.

My tactical battle scripts: https://www.dropbox.com/s/dzsmqv2pgqvu1 … h.zip?dl=1
Currently, one of my favorite games is Trimps.
So I'm the Trimper Trooper!

Thumbs up

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

Thumbs up

2019-04-11 21:04:32

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

yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

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
}
};

Thumbs up