Def functions stopping my code

how do i stop functions that has a .sleep or smt in them stop my code. like java script but in python

you use asyncio or threading. This is a fairly advanced topic, but there are good tutorials online.

i dont use any of them. should i give you my code?

import minescript as m

import time

import math

def jump():

m.player_press_jump(True)

time.sleep(0.1)

m.player_press_jump(False)

def sprint(n):

start_x, start_y, start_z = m.player_position()



m.player_press_forward(True)

m.player_press_sprint(True)



while True:

    x, y, z = m.player_position()



    distance = math.sqrt(

        (x - start_x) \*\* 2 +

        (z - start_z) \*\* 2

    )



    if distance >= n:

        m.player_press_forward(False)

        m.player_press_sprint(False)

        return



    time.sleep(0.01)

def pp():

j, k, l = m.player_position()

return j, k, l

def setb(x, y, z, block):

j, k, l = pp()



x = int(x.replace("\~", "") or "0")

y = int(y.replace("\~", "") or "0")

z = int(z.replace("\~", "") or "0")



x = j + x

y = k + y

z = l + z

x = math.floor(x)

y = math.floor(y)

z = math.floor(z)



m.execute(f"/setblock {x} {y} {z} {block}")

time.sleep(2.6)

m.execute(f"/setblock {x} {y} {z} air")

m.player_set_orientation(90, 0)

sprint(5)

jump()

setb(“~1”, “~”, “~”, “minecraft:stone”)

So you want your minecraft character to do certain actions, and in order for the timing of those actions to work right you use the sleep function?

I don’t see any problem here. time.sleep(0.1) has to temporarily stop your code, otherwise the timing would be off?

it walks and when the walk task is over it then starts to jump.
i want it to start walking and dont wait for the walking to wait. jump right away after the walking gets activated. same as the setb

So there’s 2 approaches you can use. The simple one, that I’d recommend, is you figure out when all the actions should happen. So for example, if you want to jump every 0.1 seconds, and you want to sprint every 0.01 seconds, you make sure to:
sprint, sleep 0.01,
sprint, sleep 0.01,
sprint, sleep 0.01,
sprint, sleep 0.01,
sprint, sleep 0.01,
sprint, sleep 0.01,
sprint, sleep 0.01,
sprint, sleep 0.01,
sprint, sleep 0.01,
sprint, jump, sleep 0.01,
repeat.

The second approach, which is much ‘cleaner’ but has many more opportunities for subtle bugs, is to use asyncio or threading. With asyncio you can define subprocesses, start them, and stop them. And they can sleep without pausing the other processes.

i will try and give you the resualt

it worked thanks