This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
etopsirhc's profile picture

coroutne?

Started by etopsirhc, 21 December 2012 - 03:15 PM
etopsirhc #1
Posted 21 December 2012 - 04:15 PM
any one know of a good tutorial on coroutines?
also with coroutines , is their any limit to how many things are being listened for with os.pullEvent()?
cmurtheepic #2
Posted 21 December 2012 - 06:56 PM
REALLY don't use coroutines unless use ABOSLUTELY can't useing anything ELSE ok.
alot can go wrong with coroutines. this is from experiance just warning you
Orwell #3
Posted 21 December 2012 - 09:13 PM
any one know of a good tutorial on coroutines?
also with coroutines , is their any limit to how many things are being listened for with os.pullEvent()?
1. http://lua-users.org/wiki/CoroutinesTutorial
2. no, you can listen to os.pullEvent as much as you want (not entirely sure what you mean though)
3. maybe this is what you want to know: I seem to remember that a computer can have a maximum of 50 coroutines. I don't remember the source though.
4. you can use the parallel API from CC in a lot of cases where you want to use coroutines: http://www.computercraft.info/forums2/index.php?/topic/2030-tutorial-parallel-api
etopsirhc #4
Posted 21 December 2012 - 09:50 PM
on the pull event thing, i'm wondering about multiple ones run all at once
Orwell #5
Posted 21 December 2012 - 09:52 PM
on the pull event thing, i'm wondering about multiple ones run all at once
That's no problem, they'll all be able to pull each event.
ChunLing #6
Posted 21 December 2012 - 11:51 PM
That is to say, you don't pull multiple events, you just pull the next event, whatever it is, by not specifying an event type:
t_event = {os.pullEvent()}
Then you use an if/elseif block (or function table) to react to each event type differently.
etopsirhc #7
Posted 22 December 2012 - 04:47 PM
yes! =D ty
now to make my own os … lol
KaoS #8
Posted 23 December 2012 - 08:02 AM
there is actually no limit on coroutines… the thing is that they are not running simultaneously but rather running small parts one by one, if you add enough coroutines eventually things will start running slow as 50 small snippets of code still take a while to run, I would never advise anyone to avoid coroutines, I think they are the second most useful thing in Lua and should be used accordingly