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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.