cookbook.texi (3105B)
1 @node cookbook 2 @chapter Common patterns 3 4 5 @section Hello world 6 7 @example 8 HALT 9 @end example 10 11 Will render a template without any external symbols and terminate execution immediately. 12 13 14 @anchor{handling_menus} 15 @section Handling menus and inputs 16 17 @example 18 MOUT to_foo 0 19 MOUT to_bar 1 20 MOUT upup 2 21 HALT 22 INCMP foo 0 23 INCMP bar 1 24 INCMP _ 2 25 @end example 26 27 Create three menu items, resolving the menu symbols @code{to_foo}, @code{to_bar} and @code{upup} respectively to translated text and pairing with the selectors. 28 29 Yield for client input. Then attempt to match input to selectors: 30 31 @itemize 32 @item if selector is @code{0}, execute node @code{foo}. 33 @item if selector is @code{1}, execute node @code{bar}. 34 @item if selector is @code{2}, execute previous node in stack. 35 @end itemize 36 37 38 @subsection Menu batch version 39 40 @example 41 DOWN foo 0 to_foo 42 DOWN bar 1 to_bar 43 UP 2 upup 44 @end example 45 46 This example produces exactly the same bytecode result as the @ref{handling_menus,previous example}. 47 48 49 @section Signal flow control 50 51 @example 52 LOAD foo 1 53 CATCH bar 8 1 54 MOVE baz 55 @end example 56 57 If loading the external symbol @code{foo} sets the flag @code{8}, then immediately move to @code{bar}. 58 59 Otherwise, move to @code{baz}. 60 61 62 @anchor{multiple_pages} 63 @section Multiple pages 64 65 @example 66 LOAD foo 0 67 MNEXT to_fwd 11 68 MPREV to_back 22 69 HALT 70 INCMP > 11 71 INCMP < 22 72 @end example 73 74 Load external symbol @code{foo} as a @emph{sink}. 75 76 If content spans multiple pages, resolve @code{to_fwd} and @code{to_back} as labels for lateral navigation options in the menu. 77 78 Also handle the lateral navigation inputs. 79 80 @subsection Menu batch version 81 82 @example 83 LOAD foo 0 84 NEXT 11 to_fwd 85 PREVIOUS 22 to_back 86 @end example 87 88 This example produces exactly the same bytecode result as the @ref{multiple_pages,previous example}. 89 90 91 @anchor{multiple_menus} 92 @section Multi-page menus 93 94 @example 95 MSINK 96 MNEXT to_fwd 11 97 MPREV to_back 22 98 MOUT inky 0 99 MOUT pinky 1 100 MOUT blinky 2 101 MOUT clyde 3 102 MOUT tinkywinky 4 103 MOUT dipsy 5 104 MOUT lala 6 105 MOUT pu 7 106 HALT 107 INCMP foo 0 108 INCMP foo 1 109 INCMP foo 2 110 INCMP foo 3 111 INCMP foo 4 112 INCMP foo 5 113 INCMP foo 6 114 INCMP bar 7 115 @end example 116 117 Enable splitting menu over several pages, and route all valid inputs to the @code{foo} node, except for @code{7} which is routed to the @code{bar} node. 118 119 120 @subsection Menu batch version 121 122 @example 123 MSINK 124 MNEXT to_fwd 11 125 MPREV to_back 22 126 DOWN foo 0 inky 127 DOWN foo 1 pinky 128 DOWN foo 2 blinky 129 DOWN foo 3 clyde 130 DOWN foo 4 tinkywinky 131 DOWN foo 5 dipsy 132 DOWN foo 6 lala 133 DOWN bar 7 pu 134 @end example 135 136 This example produces exactly the same bytecode result as the @ref{multiple_menus,previous example}. 137 138 139 @section Default input handler 140 141 @example 142 MOUT to_foo 0 143 HALT 144 INCMP foo 0 145 INCMP bar * 146 @end example 147 148 If input is @code{0}, route to the @code{foo}. Any other input will route to the @code{bar} node. 149 150 151 @section Graceful quit 152 153 @example 154 LOAD msg 0 155 HALT 156 @end example 157 158 Execution will stop (without error) and the node template render will be displayed. Any content returned from the execution of the @code{msg} symbol will be appended to the render. Lastly the @code{MOVE ^} will be appended automatically to the state bytecode.