Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Wait via JavaScript

TheUnproPro

Boondoggle
Staff member
Resource Team
Partner
With javascript, the only way I'm familiar with is to create a timer. Initialize a variable called _timer or something, and a variable calld _waitFinished. then in the update part, write this:

JavaScript:
_timer+= (_timer<61) ? 1 : 0;
_waitFinished = (_timer==60) ? true : _waitFinished;
After that, when the timer variable reaches 61, it'll no longer count upwards, and the _waitFinished variable will now equal true once the timer reaches 61. We add 1 on there so that it doesn't constantly set waitFinished to true. From there, you'll check if _waitFinished is equal to true, and if it is, carry on with the rest of the code :D if not, do nothing, or something else.

If you need multiple timers, then make an object containing 2 arrays, if you don't understand that let me know I"ll show you.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Javascript has a built in timer that I've used a few times without any issues or performance issues, I won't recommend loading your plugin with them but using it once in a while seems to be fine.
JavaScript:
setTimeout( function () {
// Put code here, it will run after 1500 ms or 1.5 seconds
}, 1500};
Just remember the scope changes because it has it's own function, so if you need to use code outside of this scope refrence a global. Usually the most problems are using 'this' inside of it in which case you can simply refrence this like so.
JavaScript:
var self = this;
setTimeout( function () {
self.methodName();
}, 1500};
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
It can be handy for those moments you need to wait for just a second or two before initiating your code but to be honest I don't trust it, it can be heavy on performance so you have to be smart with it, you can't just throw it in an update function and allow it to stack itself, you'll get a ton of issues.
 
Top