I've read the lua manual about what they are, but what are their inner workings? Also, do they have an actual "thread" running, or just a virtual one in lua's workings?
EDIT: Ok, I figured out what they are, but what does it mean when it says they have their own stack and its own instruction pointer?
You can have several coroutines, but only one can be run at a time. It looks a bit like multithreading, except it doesn't use actual threads and you have to manually resume each of them and tell them when to pause and go back to the main Lua context.
Basically, you can consider them like functions that you can interrupt and resume at any time. When you interrupt a coroutine, it remembers all of its local variables, and where it stopped. So if you have a function which prints the numbers from 1 to 10, have a condition which pauses it when it reaches 5, and then turn it into a coroutine, when you resume it for the first time, it will print 1, 2, 3, 4, 5. And when you resume it for the second time, it will print 6, 7, 8, 9, 10.
That's especially convenient if you want to spawn a lot of props in a short amount of time. Instead of having a function which spawns them all at once, you can turn that function into a coroutine which pauses every 10 props spawned and resumes a short moment later.
... Well, I pretty much explained that to you for nothing, because coroutines don't work in GMod. :saddowns: Garry managed to break them for some reason.
They are broken? When I tried them, they seemed to work.
[QUOTE=CmdrMatthew;26568927]They are broken? When I tried them, they seemed to work.[/QUOTE]
They seem to break if the function manipulates entities or vectors.
Sorry, you need to Log In to post a reply to this thread.