lua:start_con_handler
This is an old revision of the document!
start_con_handler( descriptor, func, … )
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().
Example 1: confirming an action (example uses luai for convenience)
luai lua>
do local function confirm_handler( ch ) sendtochar(ch, "Are you sure you want to declare yourself a butthead? [Y/n]\n\r") while true do local cmd=coroutine.yield() if cmd=="Y" then ch:mdo("gossip I AM BUTTHEAD") return elseif cmd=="n" then sendtochar(ch, "Fine, don't then.\n\r") return else sendtochar(ch, "Invalid! Please input {GY{x or {rn{x.\n\r") end end end start_con_handler( mob.descriptor, confirm_handler, mob ) end
Are you sure you want to declare yourself a butthead? [Y/n] Y You gossip 'I AM BUTTHEAD' lua>
See also constates
lua/start_con_handler.1422425774.txt.gz · Last modified: 2015/01/28 06:16 (external edit)