User Tools

Site Tools


lua:start_con_handler

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lua:start_con_handler [2015/01/28 06:15] vodurlua:start_con_handler [2015/01/28 06:22] (current) vodur
Line 3: Line 3:
 Creates a coroutine of the given function and sets it as the con state handler to the target descriptor. Any additional arguments to start_con_handler are passed to func when it is called. Creates a coroutine of the given function and sets it as the con state handler to the target descriptor. Any additional arguments to start_con_handler are passed to func when it is called.
 The con state handler handles all player input from the given descriptor. Entered commands are accessed within the handler function through coroutine.yield(). The con state handler handles all player input from the given descriptor. Entered commands are accessed within the handler function through coroutine.yield().
 +
 +The general logic is thus:
 +start_con_handler creates a coroutine of func
 +func coroutine is set as descriptor's con state handler
 +func coroutine is resumed, passing any additional start_con_handler arguments as arguments to func
 +if coroutine.yield() is called inside the handler, then the coroutine will suspend until the player enters a command, at which time the handler function resumes, with the return value of coroutine.yield() being the command that was entered.
 +If/when the handler function returns, descriptor's con state handler is cleared and con state is set back to "playing". The player can now enter normal game commands again.
 +
  
 Example 1: confirming an action (example uses luai for convenience) Example 1: confirming an action (example uses luai for convenience)
Line 40: Line 48:
 lua> lua>
 </code> </code>
 +
 +See also [[lua:scripting:examples:constates]]
lua/start_con_handler.1422425700.txt.gz · Last modified: 2015/01/28 06:15 by vodur