Wait Javascript

Avatar

By nintendocustom 13 April 2019 22:39

Member · 11 comments

Is there a way to wait a few seconds until the next command will execute?

Avatar

By nintendocustom 14 April 2019 17:14

Member · 11 comments
soulplexis wrote

I will give an example. (Might not need to use a ticks var!!)

var ticks = 0;
this.onUpdate = function() {
ticks++;
if(ticks == 20) {
-First command-
    }
if(ticks == 40) {
- second command -
}
if(ticks == 40) {
ticks = 0; 
}
}

This will execute -first command-, wait 1 second, and then execute - second command -
There are 20 ticks in 1 second and the ticks are getting +1 for every tick passed in the game. The third part is to reset the ticks so that it does not keep adding and the command repeating. other wise ticks go into infinite

I don't know if I'm just too silly but is it possible to add this to this.onEnable = function() or function onEnable()? because I can't get it to work and thank you for the answer

Avatar

By ksenomorf 14 April 2019 18:09

Member · 23 comments

I don't recommend to use soulplexis's example, cause its badly coded. Instead, you can use https://github.com/CCBlueX/LiquidBounce … Example.js


ричи

Avatar

By ksenomorf 14 April 2019 18:12

Member · 23 comments

If you want to execute an action every X seconds you can use

if(mc.thePlayer.ticksExisted % (20 * seconds) == 0)
  // code here

But setTimeout is still better


ричи