#Running code/functions asynchronously

1 messages · Page 1 of 1 (latest)

wanton hollow
#

So after about an hour of scouring the web, even consulting ai chatbots, nothing. Essentially what I want to do is, for example, on right click call 2 different functions, say one loops for 5 ticks and does x while the other loops for 10 ticks and does y at the same time. That sort of thing. Is this possible in vanilla Skript or using addons, and if not, are there any alternative methods?

wary walrus
#

you can do it with vanilla skript

#

of course, it's not proper async, they still run on the main thread, but they won't block each other

wanton hollow
#

Ok cool

#

Do you know where I can find it?

wary walrus
#

you just do exactly what you said your example

#

call two functions

#

if there's a wait in them, then they'll "run at the same time"

wanton hollow
#

Oh

#

How would it know then if I wanted them to run one after the other?

wary walrus
#

whether there's a wait in them or not

#

skript will not sit around waiting for a function to complete

#

either it finishes instantly, or it hits a wait and decides to move on, scheduling the function to finish later

#
function a():
  broadcast "a"

function b():
  wait 1 tick
  broadcast "b"

on load:
  a()
  b()
  broadcast "c"```
sends "a", "c", "b".
wanton hollow
#

Well that's not what I was expecting at all

#

But then I don't get it, what do I do if I actually need to rely on that delay inside of the function?

wary walrus
#

or use some sort of flag system with variables

wanton hollow
#

Ok I will experiment tomorrow then but that is quite annoying to have to work around

#

Or just different I guess

wary walrus
#

tbh i've never encountered an issue where it's actually an issue

#

only cases where it help (like running 2 functions at once)

wanton hollow
#

I'm just used to functions stopping code until they finish because I made an entire game on this server which I've decided to port to Skript, and I'm not entirely sure how that's gonna work

#

There's a lot of functions that happen one after the other that rely on the wait inside them

#

But I'll see what I can do

wary walrus
#

you can always just

function a():
    # do stuff
    wait 1 tick
    # do stuff
    b()```
wanton hollow
#

Alright well I guess I'll try to figure it out when it's not midnight but thanks for doing what Clyde couldn't

wanton hollow
#

Just thought of something before I go to bed so I don't forget but I will try returning a "wait" number for all funcs, then I'm not sure of the syntax but something like wait b() tick?

#

Anyway that's enough thinking for tonight

wary walrus
#

you'd have to parse as a timespan, but that'd work