lua:start_con_handler
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lua:start_con_handler [2015/01/28 06:15] – vodur | lua: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' | ||
+ | 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' | ||
+ | |||
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> | ||
</ | </ | ||
+ | |||
+ | See also [[lua: |
lua/start_con_handler.1422425700.txt.gz · Last modified: 2015/01/28 06:15 by vodur