Advertisement
Shadowolf3400

Activity Based Simple Chat for Inform7

Feb 12th, 2013
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.25 KB | None | 0 0
  1. Version 4/130219 of Activity-based Simple Chat by Shadow Wolf begins here.
  2.  
  3. Section - Chat Nodes and Activation
  4.  
  5. A chat node is a kind of thing. No-quip-chosen is a chat node.
  6. Node-type is a kind of value. The node-types are activated, non-active, choose-once, and show-once.
  7. A chat node has a node-type. The node-type of a chat node is usually activated.
  8.  
  9. A chat node has a text called quip. The quip of a chat node is usually "".
  10. A chat node has a text called prompt. The prompt of a chat node is usually ">> ".
  11. A chat node has a chat node called followup. The followup of a chat node is usually no-quip-chosen.
  12.  
  13. To activate (chosen node - a chat node): now the chosen node is activated.
  14. To deactivate (chosen node - a chat node): now the chosen node is non-active.
  15.  
  16. Section - Quittability
  17.  
  18. Chat quittability is a truth state that varies. Chat quittability is true.
  19.  
  20. To allow exiting on zero: now chat quittability is true.
  21. To forbid exiting on zero: now chat quittability is false.
  22.  
  23. To decide whether exiting on zero is allowed: if chat quittability is true, decide yes; decide no.
  24.  
  25. Section - the Table of Current Choices
  26.  
  27. Table of Current Choices
  28. result
  29. a chat node
  30. with 20 blank rows
  31.  
  32. The rowcount is a number which varies.
  33.  
  34. To link to (response - a chat node):
  35. unless response is non-active or the number of blank rows in the Table of Current Choices is 0:
  36. choose a blank row in the Table of Current Choices;
  37. now the result entry is the response;
  38.  
  39. To reset the links:
  40. blank out the whole of the Table of Current Choices.
  41.  
  42. Section - Finding Responses
  43.  
  44. Finding responses to something is an activity on chat nodes.
  45. To find responses to (C - a chat node): carry out the finding responses to activity with C.
  46.  
  47. Section - Giving Text For
  48.  
  49. Giving text for something is an activity on chat nodes.
  50. Rule for giving text for a chat node (called the current node):
  51. if the initial appearance of the current node is not "":
  52. say the initial appearance of the current node;
  53. otherwise:
  54. say "Error - no text for [the current node]".
  55.  
  56. Before giving text for a choose-once chat node (called the current node):
  57. now the current node is non-active.
  58.  
  59. To give text for (C - a chat node): carry out the giving text for activity with C.
  60.  
  61. Section - Showing Links to
  62.  
  63. Prior node is a chat node that varies.
  64.  
  65. Showing the link to something is an activity on chat nodes.
  66. Rule for showing the link to a chat node (called the current node):
  67. if the quip of the current node is not "":
  68. say the quip of the current node;
  69. otherwise:
  70. say "Error - no quip for [the current node]".
  71.  
  72. Before showing the link to a show-once chat node (called the current node):
  73. now the current node is non-active.
  74.  
  75. To show the link to (C - a chat node): carry out the showing the link to activity with C;
  76.  
  77. Section - Readchoice I6 routine
  78.  
  79. Chat prompt is text that varies. Chat prompt is ">> ";
  80.  
  81. Include (-
  82. [ ReadChoice low high i;
  83. for (::) {
  84. print (I7_string) (+ Chat prompt +);
  85. KeyboardPrimitive (buffer, parse);
  86. i = TryNumber (1);
  87. if (i >= low && i <= high) return i;
  88. else print "[Please answer by typing a number between ", low, " and ", high, ".]^";
  89. }
  90. ];
  91. -).
  92.  
  93. To decide what number is the choice made from (low value - a number) to (high value - a number): (- ReadChoice ( {low value}, {high value} ) -).
  94.  
  95. Section - Starting a Conversation
  96.  
  97. To start a conversation with (current node - a chat node):
  98. let previous node be no-quip-chosen;
  99. let next node be no-quip-chosen;
  100. while current node is not no-quip-chosen:
  101. give text for the current node;
  102. say "[paragraph break]";
  103. if the followup of the current node is not no-quip-chosen:
  104. now the current node is the followup of the current node;
  105. otherwise:
  106. reset the links;
  107. find responses to the current node;
  108. if the Table of Current Choices is empty:
  109. now the current node is no-quip-chosen;
  110. otherwise:
  111. now the prior node is the current node;
  112. sort the Table of Current Choices in result order; [shuffles all blank rows to the bottom]
  113. let rowcount be the number of filled rows in the Table of Current Choices;
  114. repeat with choice running from 1 to the rowcount:
  115. say "[choice]) [run paragraph on]";
  116. choose row choice in the Table of Current Choices;
  117. show the link to the result entry;
  118. say "[line break]";
  119. let choice made be 0;
  120. now chat prompt is the prompt of the current node;
  121. if exiting on zero is allowed:
  122. say "[italic type]([simple chat zero option])[roman type][line break]";
  123. now choice made is the choice made from 0 to rowcount;
  124. otherwise:
  125. now choice made is the choice made from 1 to rowcount;
  126. if choice made is 0:
  127. now next node is no-quip-chosen;
  128. say "[line break][run paragraph on]";
  129. otherwise:
  130. now next node is result in row choice made of the Table of Current Choices;
  131. now previous node is current node;
  132. now current node is next node.
  133.  
  134.  
  135. zero-option-saying is an activity.
  136. The last for zero-option-saying rule (this is the default zero option rule): say "or 0 to say nothing[run paragraph on]".
  137. To say simple chat zero option: carry out the zero-option-saying activity.
  138.  
  139. Section - German (for use with German by Team GerX)
  140.  
  141. This is the German zero option rule: say "oder 0 um nichts zu sagen[run paragraph on]".
  142. The German zero option rule is listed instead of the default zero option rule in the for zero-option-saying rulebook.
  143.  
  144. Section - French (for use with French by Eric Forgeot)
  145.  
  146. This is the French zero option rule: say "ou 0 pour ne rien dire[run paragraph on]".
  147. The French zero option rule is listed instead of the default zero option rule in the for zero-option-saying rulebook.
  148.  
  149.  
  150. Activity-based Simple Chat ends here.
  151.  
  152. ---- DOCUMENTATION ----
  153.  
  154. Section: Changes from Simple Chat
  155.  
  156. Activity-based Simple Chat is a rewrite of Mark Tilford's Simple Chat extension. It uses activities where Simple Chat uses actions, in order to simplify the process of writing rules for chat nodes. Among other things, this means that the original player action (including noun, second noun, etc.) that initiates the conversation is always available rather than being overridden by nested actions.
  157.  
  158. It also turns chat nodes into things instead of values, allowing standard object properties to provide link names and text for chat nodes - so many chat nodes will require no additional rules except to build the link menu.
  159.  
  160. The text for the zero option is now also an activity ("zero-option-saying"). This allows you to override the text for specific kinds of nodes, etc., e.g.
  161.  
  162. Rule for zero-option-saying while the prior node is a help node: say "or 0 to quit[run paragraph on]"
  163.  
  164. I've also updated some of the table handling, to avoid maintaining a global row count and in order to simplify the syntax. Some other unnecessary globals have also been removed.
  165.  
  166. For questions, bug reports, etc, contact <shadowolf3400@gmail.com>
  167.  
  168. Section: Using Chat Nodes
  169.  
  170. A "chat node" is a conversational object, typically a quip spoken by the player, with a response from an NPC. By default, the "quip" property will be the player's quip (as shown by the extension's menus), while the "initial appearance" property is the response text. This makes defining a basic chat node fairly simple:
  171.  
  172. Node-harry-hello is a chat node with quip "'Hello, Harry.'". "Harry says, 'Hi, player! What's up?'".
  173.  
  174. (Note that with this syntax it is important to be sure there is a period between the quip and the initial appearance. In particular, if you have single quotes around the quip, you need to ensure that there is a period outside of the quotes, as above. Otherwise the compiler will not set the property correctly.
  175.  
  176. You can override the use of the quip property by providing a "Rule for showing the link to ___:" These rules can be qualified with the usual clauses. In particular, if you want to base the text on the chat node just displayed, you can test the "prior node" value:
  177.  
  178. Rule for showing the link to harry-good-bye when the prior node is harry-hows-tricks: say "'Well then, good-bye.'".
  179.  
  180. To override the use of initial appearance for the NPC response, create "Rule for giving text for ___:" Again, rules can be qualified with the usual clauses.
  181.  
  182. To build the menu of player choices, create a "Rule for finding responses to ___:" For each quip the player may pick, call the "link to ___" phrase for the appropriate node. Non-active nodes (see the chat node types below) will not be displayed. Additional conditional checks can be built into this rule as well. If you want to copy the responses of another node, you can call "Find responses to ___." Be careful to avoid circular loops.
  183.  
  184. If there is no "rule for finding responses", then the conversation will end. There can be at most twenty links displayed for a given node (should be plenty)! But this can be increased by extending the Table of Current Choices with additional blank rows.
  185.  
  186. Chat node types: There are four chat node states: activated, non-active, shown-once, and choose-once. Activated is the default with normal behavior. Non-active nodes will never be linked to until the state is explicitly changed (You can use the phrases "activate ___" or "deactivate ___"). A shown-once node will become non-active once the link has been displayed once - if the player doesn't select it, they will never get the option again. A choose-once node will become non-active only once it has been picked by the player, after which it will not be displayed again.
  187.  
  188. To begin a conversation, simply use the phrase "Start a conversation with ___" (where the blank is the first node of the conversation). This can be used in the rule for a "Talk to..." action, for instance.
  189.  
  190. Section: Customizing the prompt
  191.  
  192. This is a pure enhancement over the original Simple Chat. Every node has a "prompt" property, which can be used to override the prompt for all nodes ("The prompt for a chat node is usually ___") or on a node-by-node basis. (Or you could create different sub-kinds of nodes with special prompts.)
  193.  
  194. Section: Exiting a conversation
  195.  
  196. As with Simple Chat, the default is that the player can choose "0" to exit the menus and return to the normal prompt. The code can instead "Forbid exiting on zero" to turn this behavior off, or "Allow exiting on zero" to turn this behavior on again. I've included the German and French translations of the "simple chat zero option" text.
  197.  
  198. Section: Followups
  199.  
  200. You can now define a followup to a node. If a followup for a node is specified, then after the first node's text is printed, the followup node will immediately be executed - there will be no menu displayed for the original node. You define the followup with "The followup of chat-node-first is chat-node-followup".
  201.  
  202. Example: *Simplest Chat - shows the basic functionality. This parallels the example in Mark Tilford's version.
  203.  
  204. *: "Simplest Chat" by Shadow Wolf
  205.  
  206. Include Activity-based Simple Chat by Shadow Wolf.
  207.  
  208. Talking to is an action applying to one visible thing.
  209.  
  210. Understand "talk to [someone]" as talking to.
  211. Report talking to: say "You have nothing to say.".
  212.  
  213. Living Room is a room. Larry is a man in Living Room.
  214.  
  215. chat-hello-larry is a chat node. "Larry looks up as you approach him."
  216. Rule for finding responses to chat-hello-larry:
  217. link to chat-hows-tricks; link to chat-good-bye.
  218.  
  219. chat-hows-tricks is a chat node with quip "'How's tricks?' ". "'Just fine.'".
  220. Rule for finding responses to chat-hows-tricks: link to chat-good-bye.
  221. Rule for giving text for chat-hows-tricks: deactivate chat-hows-tricks; continue the activity.
  222.  
  223. chat-good-bye is a chat node with quip "'Good bye.' ". "'You too.'".
  224. Rule for showing the link to chat-good-bye when the prior node is chat-hows-tricks:
  225. say "'Well then, good bye.' ".
  226.  
  227. Instead of talking to Larry: start a conversation with chat-hello-larry.
  228.  
  229. Test me with "talk to larry / 1 / 1 / talk to larry / 1 / talk to larry / 0".
  230.  
  231. Example: **Less Simple Chat - Shows some of the more advanced functionality. Functionally identical to the example in Tilford's extension, although the order of menu options is likely different.
  232.  
  233. *: "Less Simple Chat" by Shadow Wolf
  234.  
  235. Include Activity-based Simple Chat by Shadow Wolf.
  236.  
  237. Talking to is an action applying to one visible thing.
  238.  
  239. Understand "talk to [someone]" as talking to.
  240. Report talking to: say "You have nothing to say.".
  241.  
  242. When play begins:
  243. forbid exiting on zero.
  244.  
  245. Living Room is a room. Harry is a man in the Living Room. He carries Finnegans Wake.
  246.  
  247. Harry-chat-hello is a chat node. "Harry looks up as you approach him."
  248. Rule for finding responses to Harry-chat-hello:
  249. link to Harry-chat-book; link to Harry-chat-fire; link to Harry-chat-again; link to Harry-chat-goodbye.
  250.  
  251. Harry-chat-book is a choose-once chat node with quip "What was that book you told me about?". "'It's by some guy called Finnegan Wake, and I think it's in Irish or something. Do you want it?'"
  252. Rule for finding responses to Harry-chat-book:
  253. link to Harry-chat-want-it; link to Harry-chat-dont-want.
  254.  
  255. Harry-chat-want-it is a chat node with quip "'Sure.' ".
  256. Rule for giving text for Harry-chat-want-it:
  257. move Finnegans Wake to player;
  258. say "Harry hands the book to you. ".
  259. Rule for finding responses to Harry-chat-want-it: Find responses to Harry-chat-hello.
  260.  
  261. Harry-chat-dont-want is a chat node with quip "'No, thanks.' ". "Harry sighs. 'I'm never going to get rid of it.'"
  262. Rule for finding responses to Harry-chat-dont-want: Find responses to Harry-chat-hello.
  263.  
  264. Harry-chat-fire is a show-once chat node with quip "'Run! Fire!'". "'We are only pixels on a two-dimensional screen. There is nowhere to run to.' Harry's words shatter the fourth wall.".
  265. Rule for finding responses to Harry-chat-fire: Find responses to Harry-chat-hello.
  266.  
  267. Harry-chat-again is a non-active chat node with quip "'Didn't we have this conversation before?'". "'The world is one big circle, and we are doomed to repeat ourselves.'"
  268. Rule for finding responses to Harry-chat-again: Find responses to Harry-chat-hello.
  269.  
  270. Harry-chat-goodbye is a chat node with quip "'See you later, Harry.'". "'Later!'"
  271. After giving text for harry-chat-goodbye: activate Harry-chat-again.
  272.  
  273. Instead of talking to Harry: start a conversation with Harry-chat-hello.
  274.  
  275. Test me with "talk to harry/2/2/talk to harry/2/1/1/2/i/talk to harry/2".
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement