lua:start_con_handler
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
lua:start_con_handler [2015/01/28 06:14] – created 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 34: | Line 42: | ||
end | end | ||
</ | </ | ||
+ | < | ||
+ | Are you sure you want to declare yourself a butthead? [Y/n] | ||
+ | Y | ||
+ | You gossip 'I AM BUTTHEAD' | ||
+ | lua> | ||
+ | </ | ||
+ | |||
+ | See also [[lua: |
lua/start_con_handler.1422425656.txt.gz · Last modified: 2015/01/28 06:14 by vodur