Jump to content

How to create simple timer?


Recommended Posts

  • 2 months later...
  • 1 month later...
Posted

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);
Posted (edited)
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
Posted
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

Posted
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

  • 1 year later...

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.
×
×
  • Create New...