I'm currently working on multitasking.
How would you pass arguments to a coroutine? You can't call the function with arguments, and resuming it will wait for coroutine.yeild, not the arguments. Should I simply add an 'in between' function that handles this?
Coroutines & tArgs?
Started by KingofGamesYami, Nov 26 2014 04:26 PM
3 replies to this topic
#1
Posted 26 November 2014 - 04:26 PM
#2
Posted 26 November 2014 - 05:10 PM
You pass arguments to a coroutine through coroutine.resume. If it is the first time resuming the coroutine, the args you resume it with are passed in as if you were calling the original function with those args. If you have already resumed it, then it must have just called coroutine.yield() for you to be running any code, and resuming it will cause whatever you resume it with to be returned by the coroutine.yield() called from the coroutine.
#3
Posted 26 November 2014 - 05:17 PM
So, just to be clear...
Will print
local co = coroutine.create( function( ... ) print( textutils.serialize( { ... } ) ) end )
coroutine.resume( co, "hello" )
Will print
{
Hello
}
#4
Posted 26 November 2014 - 05:19 PM
Technically, no (capitalization & table formatting are off). But close enough, yeah.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











