Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What does spawn() function do and how do I use it?

Asked by 5 years ago

I looked here spawn() function and it doesn't give a lot of information, can someone give an example on how to use it/how it works and what it does?

0
spawn(f) schedules a new thread with body function f User#24403 69 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago

A basic way to put it, its an updated coroutine. I use them as basic code jumps where i can execute something at the same time.

Dont use to many of these; it can actually create lag.

So a basic example:

while true do
    wait()
    print'1'
end

print'2'

So in normal terms the print'2' will never be executed but...

spawn(function()
    while true do
        wait()
        print'1'
    end
end)

print'2'

if we do it like above the console will look somewhat like this...

--> 1 --> 2 --> 1 --> 1 --> etc

If you have any more questions let me know in the comments and i will get back with you asap

0
So spawn() basically allows 2 things to be ran at once. LoganboyInCO 150 — 5y
0
No. No 2 things can be run at the exact same time. DinozCreates 1070 — 5y
0
So it probably has as much purpose as do while loops Tymberlejk 143 — 5y
Ad

Answer this question