0xNull

How to create simple timer?

Recommended Posts

If you want to create a timer lets say which spawns a vehicle after 3 seconds this is the way to go.

setTimeout(() => {
//spawn vehicle here
}, 3000);

Share this post


Link to post
Share on other sites
let myTimer = null;
myTimer = setInterval(() => {
	// Spawn Vehicle
	clearInterval(myTimer);
	myTimer = null;
}, 3000);

This should work, after 3 seconds, it performs the function and clears the range (runs only once)

Edited by LeozinH1

Share this post


Link to post
Share on other sites
Am 19.5.2018 um 22:10 schrieb LeozinH1:
let myTimer = null;
myTimer = setInterval(() => {
	// Spawn Vehicle
	clearInterval(myTimer);
	myTimer = null;
}, 3000);

This should work, after 3 seconds, it performs the function and clears the range (runs only once)

No need for an interval, just use the timeout function

Share this post


Link to post
Share on other sites
5 hours ago, Chris0x said:

No need for an interval, just use the timeout function

 

It is true. I thought the settimeout was looping. I've never tried to use it :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.