coroutine.resume

From GMod Wiki

Revision as of 06:36, 2 February 2011 by Donkie (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax coroutine.resume( Thread thread )
Where is this used?
Description:
(Re)starts the execution of a coroutine, changing its state from suspended to running. (Note: you cannot resume a dead coroutine.)
Returns: Boolean false and an error, if you are trying to resume a dead coroutine; true and arguments passed to the yield() otherwise
Part of Library: Corout
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Coroutine.resume]Coroutine.resume [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

 
  co = coroutine.create(function ()
           for i=1,10 do
             print("co", i)
             coroutine.yield()
           end
         end)
 
coroutine.resume(co)    // Output: co   1
coroutine.resume(co)    // Output: co   2
coroutine.resume(co)    // Output: co   3
...
coroutine.resume(co)    // Output: co   10
coroutine.resume(co)    // prints nothing, but returns false plus an error message 
                        // "cannot resume dead coroutine"
 

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox