#how to execute commands with one second delay with gametest?

33 messages · Page 1 of 1 (latest)

silver arch
#

Can be done?

lofty goblet
#

wait x ticks

#

use tick event for that

silver arch
lofty goblet
#

can u use TickEvent?

silver arch
brave vector
#

I guess you could just count to 20? catshrug Did they ever add a better interface to delayed executions?

jolly forum
#

My overcomplicated solution.
We know that minecraft runs things at 20 ticks a second.

#

So if we run a command every tick that adds a score to the player and reset it at 20

#

We can detect when one second has passed.

#

Like this.

/title @p[scores={tick=20..}] title one second has passed

lofty goblet
#

? script tick awaition

silver sparrowBOT
#
Tick Awaition

since 1.19.50, we recieved two new methods that can be used for delayed function execution

// like setTimeout
system.run( func, tickDelay )

// like setInterval
system.runSchedule( func, tickDelay )

// like clearTimeout
system.clearRun( timeout )

// like clearInterval
system.cleatRunSchedule( interval ) 

Example

const TICKS_IN_SEC = 20

const run = system.run( () => {
    console.warn( "timeout" )
}, TICKS_IN_SEC )

const runSchedule = system.runSchedule( () => {
    console.warn( "interval" )
}, TICKS_IN_SEC )
system.clearRun( run )
system.cleatRunSchedule( runSchedule )
lofty goblet
rose wagon
#
system.run(function() {
// code
}, 20)
#

This change just went live on stable 1.19.40

lofty goblet
rose wagon
#

Released today

lofty goblet
rose wagon
#

Just system.run atm

lofty goblet
#

thx for answer

rose wagon
#

I actually don't know if it allows you to specify the delay

lofty goblet
#

bruh

rose wagon
#

That might've been a 1.19.50 thing

lofty goblet
#

that was what i asking for

#

😂

#

np

#

i will try

rose wagon
#

Yeah, im not sure

#

I thought it did but i just reread that and now idk