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?
#Running code/functions asynchronously
1 messages · Page 1 of 1 (latest)
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
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"
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".
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?
you call something else at the end of the function
or use some sort of flag system with variables
Ok I will experiment tomorrow then but that is quite annoying to have to work around
Or just different I guess
tbh i've never encountered an issue where it's actually an issue
only cases where it help (like running 2 functions at once)
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
you can always just
function a():
# do stuff
wait 1 tick
# do stuff
b()```
Alright well I guess I'll try to figure it out when it's not midnight but thanks for doing what Clyde couldn't
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
you'd have to parse as a timespan, but that'd work