KevinLuWX
(KevinLuWX)
September 28, 2019, 2:01am
#1
How do I make a coroutine that runs from the start every time it is called, instead of resuming the previous run? Basically make it run like a function would when it’s called. I’m new to coroutines, need guidance…
Right now if I call the coroutine again before the previous run finishes, it will resume the previous run instead of starting a new run from the top.
To make it start from the top each time, create a new thread each time.
local function Receiver(origin,bs,destination)
--the code
end
and to create it each time
local function ToQvl(hit)
--before
local thread = coroutine.create(Receiver)
coroutine.resume(thread,"DP",hit,"QV")
--after
end
1 Like
KevinLuWX
(KevinLuWX)
September 28, 2019, 3:48am
#3
It does initiate the coroutine, but doesn’t run the line after until the coroutine has completed. How do I make it so it continues running
You call Receiver
, so are you sure its the thread that is being run, and not where you called Receiver?
Also, you can put your code in the message,
```
local h = print()
```
becomes
local h = print()
KevinLuWX
(KevinLuWX)
September 28, 2019, 4:01am
#5
My bad forgot to take out that line.