Simple Chat question [i7]

I’m using Mark Tilford’s Simple Chat extension. It’s so simple! Thanks Mark.

I’m forbidding exiting on 0, and making a ‘goodbye’ node for each NPC which always remains active. How can I get i7 to check if there’s only one active chat node (this will always be the goodbye node), and say “You have nothing else to say.” instead of entering a conversation?

Thanks for reading.

I think you want to use some code like this:

try silently finding responses to current node; if rowcount is 1:
The if-clause will only run if there is exactly one response to the chat node “current node”. (Let me know if you cannot figure out how to actually use this stuff. :slight_smile: )

Thanks for the quick response. Is this code to insert into a ‘report giving text’ bit? If so, it’s not what I need.

Just to clarify, I want the ‘talk to’ command to fail if the NPC the player is trying to talk to only has one active chat node. So I don’t need to do anything during a conversation, just before it.

If your code is designed to do that, sorry for misunderstanding, and could you tell me where I’d use it?

It depends on how you have implemented “talk to”, of course. If you have code like this:

Instead of talking to larry: run a conversation from hello larry.

then what you need to do is see how many replies there are to the “hello larry” quip. Right? And you could do that using the code I’ve posted. So something like this should work (I’d like to stress that although I am the maintainer of Simple Chat, I haven’t used it for a while, and I’m posting this without having Inform 7 running, so I might make mistakes!):

Before talking to larry: try silently finding responses to hello larry; if rowcount is 1: say "You have nothing else to say." instead.
If you have a bunch of NPCs, you’ve probably given all of them a chat node that varies – say, “conversation starter” – and you could write something like this:

Instead of talking to someone: try silently finding responses to conversation starter of the noun; if rowcount is 1: say "You have nothing else to say."; otherwise: run a conversation from conversation starter of the noun.

Now this is weird.

Your code (which I should have understood before, sorry about that!) works perfectly - every other time!

To see what I mean, run this code. It’s the ‘simplest chat’ documentation example with ‘forbid exiting on 0’ and your before code added:

[code]Include Simple Chat by Mark Tilford.

When play begins:
forbid exiting on zero.

Talking to is an action applying to one visible thing.

Understand “talk to [someone]” as talking to.
Report talking to: say “You have nothing to say.”.

Living Room is a room. Larry is a man in Living Room.

Before talking to larry:
try silently finding responses to hello larry;
if rowcount is 1, say “You have nothing else to say.” instead.

Hello larry, hows tricks, good bye are chat nodes.

Report giving text for hello larry: instead say “Larry looks up as you approach him.”.
Carry out finding responses to hello larry: link to hows tricks; link to good bye.

Report giving link to hows tricks: say "‘How’s tricks?’ " instead.
Report giving text for hows tricks: deactivate hows tricks; say “‘Just fine.’” instead.
Carry out finding responses to hows tricks: link to good bye.

Report giving link to good bye: instead say "‘Good bye.’ ".
Report giving link to good bye when second chat node is hows tricks: instead say "‘Well then, good bye.’ ".
Report giving text for good bye: instead say “‘You too.’”.

Instead of talking to larry: run a conversation from hello larry.

Test me with “talk to larry / 1 / 1 / talk to larry / 1 / talk to larry / 0”.[/code]

When there is only one option available it will give the ‘nothing to say’ message the first time. Then if you try talking to larry again, it will enter the conversation. And so ad infinitum. Please note I have not used the colons and indentations system in your before code as they wouldn’t compile and I don’t personally use them, but (I think) the code should still do the same thing.

Sorry to be a pain, any ideas on this?

I’ll try to look at it later today, with Inform actually open!

You can use the begin/end syntax, which looks like this.

Before talking to larry: try silently finding responses to hello larry; if rowcount is 1 begin; say "You have nothing else to say." instead; end if.

Instead of talking to someone: try silently finding responses to conversation starter of the noun; if rowcount is 1 begin; say "You have nothing else to say."; otherwise; run a conversation from conversation starter of the noun; end if.

I prefer this syntax over the colon indentation one and strongly recommend it.

Try this.

[code]“Test”

Include Simple Chat by Mark Tilford.

When play begins: forbid exiting on zero.

Talking to is an action applying to one visible thing.

Understand “Talk to [someone]” as talking to.
Report talking to: say “You have nothing to say.”.

Living Room is a room. Larry is a man in Living Room.

Before talking to larry:
try silently finding responses to hello larry;
if rowcount is 1 begin;
reset the links;
say “You have nothing else to say.” instead;
end if.

Hello larry, hows tricks, good bye are chat nodes.

Report giving text for hello larry: say “Larry looks up as you approach him.” instead.
Carry out finding responses to hello larry: link to hows tricks; link to good bye.

Report giving link to hows tricks: say "‘How’s tricks?’ " instead.
Report giving text for hows tricks: deactivate hows tricks; say “‘Just fine.’” instead.
Carry out finding responses to hows tricks: link to good bye.

Report giving link to good bye: say "‘Good bye.’ " instead.
Report giving link to good bye when second chat node is hows tricks: say "‘Well then, good bye.’ " instead.
Report giving text for good bye: say “‘You too.’” instead.

Instead of talking to larry: run a conversation from hello larry.

Test me with “talk to larry / 1 / 1 / talk to larry / talk to larry”.[/code]

It seems that our good friend Victor Gijsbers forgot to “reset the links”, so the rowcount was correctly increased to one when “finding responses to hello larry” but not reset to zero afterwards.

Hope this helps.

All working perfectly. Many thanks to both of you!

Ah, well… I said that it was some time ago that I looked at the code. :blush:

No worries! We can’t all be looking at all of the code all of the time!

While looking through this extension, I noticed that it has some line break issues and me being me, I made an attempt to sort it out. This is what I came up with.

[spoiler][code]Version 4 of Simple Chat by Mark Tilford begins here.

[Please note that this extension is currently maintained by Victor Gijsbers. Bug reports and feature requests should be sent to victor@lilith.cc.]

Section - Conversation exiting

Conversation exiting is a kind of value. The conversation exitings are player may exit upon zero, player may not exit.

Current exiting is a conversation exiting that varies. Current exiting is player may exit upon zero.

To allow exiting on zero: now current exiting is player may exit upon zero.
To forbid exiting on zero: now current exiting is player may not exit.

To decide whether exiting on zero is allowed:
if current exiting is player may exit upon zero, decide yes;
decide no.

Section - Chat nodes

Chat node is a kind of value.

The chat nodes are no quip chosen.

Section - Chat node activation

Activatedness is a kind of value. The activatednesses are sc-active, sc-inactive, sc-once and sc-shown-once.

A chat node has an activatedness. The activatedness of a chat node is usually sc-active.

To activate (chosen node - a chat node): now chosen node is sc-active.
To deactivate (chosen node - a chat node): now chosen node is sc-inactive.

Section - Setting up the Table of Current Choices

Table of Current Choices
Result
a chat node
with 20 blank rows

The rowcount is a number which varies.

To link to (response - a chat node):
unless response is sc-inactive:
increase rowcount by 1;
if rowcount <= the number of rows in table of current choices:
now result in row rowcount of table of current choices is response;
otherwise:
decrease rowcount by 1.

To reset the links:
blank out the whole of the Table of Current Choices;
now rowcount is 0.

Section - Finding responses to

Finding responses to is an action applying to a chat node.
Carry out finding responses to: do nothing.

Section - Giving text for

First chat node is a chat node that varies.
Second chat node is a chat node that varies.

Giving text for is an action applying to a chat node.

First report giving text for: [Nodes with sc-once set are deactivated when they are chosen.]
if the chat node understood is sc-once:
now chat node understood is sc-inactive.

Report giving text for: say “Error: no text for [chat node understood].”.
Report giving text for no quip chosen: do nothing instead.

Section - Giving link to

Giving link to is an action applying to a chat node.

First report giving link to: [Nodes with sc-shown-once set are deactivated when they are displayed in the menu.]
if the chat node understood is sc-shown-once:
now chat node understood is sc-inactive.

Report giving link to: say "Error: no link text for [chat node understood]. ".

Section - Preparing

Preparing is an action applying to a chat node.

Carry out preparing:
activate the chat node understood.

Section - Readchoice I6 routine

Include (-
[ ReadChoice low high i;
for (::slight_smile: {
print ">> ";
KeyboardPrimitive (buffer, parse);
i = TryNumber (1);
if (i >= low && i <= high) return i;
else print "[Please answer by typing a number between ", low, " and ", high, “.]^^”;
}
];
-).

To decide what number is the choice made from (low value - a number) to (high value - a number): (- ReadChoice ( {low value}, {high value} ) -).

Section - Running a conversation from

To run a conversation from (current node - a chat node):
let previous node be no quip chosen;
let next node be no quip chosen;
while current node is not no quip chosen:
try giving text for current node;
reset the links;
try silently finding responses to current node;
if rowcount is greater than 0:
repeat with current row running from 1 to rowcount:
say “[current row]) [run paragraph on]”;
now next node is result in row current row of table of current choices;
now first chat node is next node;
now second chat node is current node;
try giving link to next node;
let choice made be 0;
if exiting on zero is allowed:
say “[italic type]([simple chat zero option])[roman type]”;
say paragraph break;
now choice made is the choice made from 0 to rowcount;
otherwise:
say command clarification break;
now choice made is the choice made from 1 to rowcount;
if choice made is 0:
now next node is no quip chosen;
say command clarification break;
otherwise:
now next node is result in row choice made of table of current choices;
now previous node is current node;
now current node is next node;
otherwise:
now current node is no quip chosen.

To say simple chat zero option: say “or 0 to say nothing”.

Section - German (for use with German by Team GerX)

To say simple chat zero option: say “oder 0 um nichts zu sagen”.

Section - French (for use with French by Eric Forgeot)

To say simple chat zero option: say “ou 0 pour ne rien dire”.

Simple Chat ends here.

---- DOCUMENTATION ----

Section: Using Simple Chat

This is an extension to handle simple menu-based conversations, or anything else for which you want to use an in-text menu. Simple Chat differs from Emily Short’s Menus in that the latter replaces the normal game window by a menu navigated with the arrow keys, whereas Simple Chat prints a list of numbered options in the game text itself. In addition, Simple Chat makes it easy to set up the kind of connections that one needs for a menu-based conversation.

The basic kind of value introduced by the extension is the chat node. For each thing the player can say, the author defines a chat node value: “Harry-on-aliens is a chat node”. To keep things organized, consider starting the name of each node with the name of the character the player is talking with, or something else related to the overall conversation.

For all chat nodes, you must put in an “Instead of giving text for ___: …” override. This function is to display the text for when the player is at that chat node.

For all chat nodes which are linked from some other chat node (which will generally be all those which are not ones which start conversations), you must put in an “Report giving link to ___: … instead” override. This function is to display the text which will be listed in the menu. If you want the text to vary depending on the previous chat node, you may instead use “Report giving link to ___ when second chat node is ___:”.

For all chat nodes which are to display a menu, you must put in a “Carry out finding responses to ___:” override. For each chat node the player can go to from here, put in “link to ___”. If no chat nodes are linked to, then the conversation will stop. You can use conditionals in these phrases to change the contents of the menu based on the state of the game, e.g., “if player wears the weird hat, link to ___”.

The “link to " phrase has no effect if the chat node is not active. Every chat node has an activatedness: either sc-active, sc-inactive, sc-once or sc-shown-once. These can be set at the beginning of the game with declarations like "_ is sc-once”. If no declaration is made, a chat node starts as sc-active.

An sc-active chat node is shown when it is linked to, while an sc-inactive chat node is not shown. Chat nodes that are sc-once are shown normally, but will be set to sc-inactive once they are chosen, thus disappearing from the menu. Chat nodes that are sc-shown-once are also shown normally, but will be set to sc-inactive after being displayed in a menu, whether they are chosen or not: in effect, the player has only one chance to choose them.

During play, chat nodes can be actived or deactived by “activate ___” and “deactivate ___”. (These are easier-to-read equivalents of “now ___ is sc-active” and “now ___ is sc-inactive”.)

Finally, to show the menu starting from a certain chat node, put in “run a conversation from ___”. Simple Chat does not define a “talking to” action – this is left to the author of the game.

There can be at most twenty links printed from any chat node. Any more will be silently dropped. This number can be increased by adding rows to the Table Of Current Choices.

By default, the player can get out of any menu by choosing 0. To change this for all menus, put “When play begins: allow exiting on zero.” at the beginning of the file. To change this for some menus, put “allow exiting on zero;” or “forbid exiting on zero;” in the appropriate “give text for …” or “find responses to …” block.

The only text a user should ever see which is printed by Simple Chat is “or 0 to say nothing”. In games using the German or French translation extension, this is replaced by “oder 0 um nichts zu sagen” and “ou 0 pour ne rien dire” respectively. Other non-English games should add a translation by adding something like the following line:

To say simple chat zero option:
	say "or 0 to say nothing[run paragraph on]".

Section: Contact

The current maintainer of Simple Chat is Victor Gijsbers. You can reach him at victor@lilith.cc.

Section: Change log

Version 4: First version released by Victor Gijsbers.

  • Code cleanup.
  • Use options were removed. (They led to a confusing double functionality.)
  • Implemented activatedness as a property of chat nodes, rather than as a relation between chat nodes and property values. Added sc-inactive, sc-once and sc-shown-once for easier control of when chat nodes are shown.
  • Added a ‘parser message’ to the routine which asks for a number: some players did not see that the command prompt had changed, or did not understand what it meant.
  • Rewritten the documentation.
  • Reworked and replaced the example games.
  • Increased the maximum number of nodes in a single menu from 9 to 20.
  • A number of changes to the internal workings of the extension.
  • Easier internationalisation.
    Version 4 is not necessarily compatible with code written for previous versions!

Version 3: Tentative version by Mark Tilford to make Inform 7 compatible with release 6E72 of Inform 7. Not released on the Inform 7 website. Version 3 is not necessarily compatible with code written for previous versions!

Example: * Simplest Chat - Have a simple conversation with Larry. Shows how to use the basic functionality of Simple Chat.

*: "Simplest Chat" by Mark Tilford

Include Simple Chat by Mark Tilford.

Talking to is an action applying to one visible thing.

Understand "talk to [someone]" as talking to.
Report talking to: say "You have nothing to say.".

Living Room is a room. Larry is a man in Living Room.

Hello larry, hows tricks, good bye are chat nodes.

Report giving text for hello larry: instead say "Larry looks up as you approach him.".
Carry out finding responses to hello larry: link to hows tricks; link to good bye.

Report giving link to hows tricks: say "'How's tricks?' " instead.
Report giving text for hows tricks: deactivate hows tricks; say "'Just fine.'" instead.
Carry out finding responses to hows tricks: link to good bye.

Report giving link to good bye: instead say "'Good bye.' ".
Report giving link to good bye when second chat node is hows tricks: instead say "'Well then, good bye.' ".
Report giving text for good bye: instead say "'You too.'".

Instead of talking to larry: run a conversation from hello larry.

Test me with "talk to larry / 1 / 1 / talk to larry / 1 / talk to larry / 0".

Example: ** Less Simple Chat - Shows off a few of the more advanced features of Simple Chat: nodes that get activated during play; nodes that can be chosen only once, or appear in the menu only once; mixing other actions with simple chat conversations.

*: "Less Simple Chat" by Victor Gijsbers

Include Simple Chat by Mark Tilford.

Talking to is an action applying to one visible thing.

Understand "talk to [someone]" as talking to.
Report talking to: say "You have nothing to say.".

When play begins:
	forbid exiting on zero.

Living room is a room. Harry is a man in Living Room.

Finnegans Wake is a thing. Harry carries Finnegans Wake.

Chat-hello-Harry, chat-book, chat-I-want-it, chat-I-do-not-want-it, chat-fire, chat-goodbye and chat-again are chat nodes. 

Chat-book is sc-once. [We can choose this option only once.] Chat-fire is sc-shown-once. [We must choose it immediately or we can never choose it again.] Chat-again is sc-inactive. [This is only shown once it has been activated.] 

Instead of talking to Harry: run a conversation from chat-hello-harry.

Report giving text for chat-hello-harry: instead say "Harry looks up as you approach him.".
Carry out finding responses to chat-hello-harry: link to chat-book; link to chat-fire; link to chat-again; link to chat-goodbye.

Report giving link to chat-book: instead say "'What was that book you told me about?' ".
Report giving text for chat-book: instead say "'It's by some guy called Finnegan Wake, and I think it's in Irish or something. Do you want it?'".
Carry out finding responses to chat-book: link to chat-I-want-it; link to chat-I-do-not-want-it.

Report giving link to chat-I-want-it: instead say "'Sure.' ".
Report giving text for chat-I-want-it: move Finnegans Wake to player; instead say "Harry hands the book to you.".
Carry out finding responses to chat-I-want-it: try finding responses to chat-hello-harry instead.

Report giving link to chat-I-do-not-want-it: instead say "'No, thanks.' ".
Report giving text for chat-I-do-not-want-it: instead say "Harry sighs. 'I'm never going to get rid of it.'".
Carry out finding responses to chat-I-do-not-want-it: try finding responses to chat-hello-harry instead.

Report giving link to chat-fire: instead say "'Run! Fire!' ".
Report giving text for chat-fire: instead say "'We are only pixels on a two-dimensional screen. There is nowhere to run to.' Harry's words shatter the fourth wall.".
Carry out finding responses to chat-fire: try finding responses to chat-hello-harry instead

Report giving link to chat-again: instead say "'Didn't we have this conversation before?' ".
Report giving text for chat-again: instead say "'The world is one big circle, and we are doomed to repeat ourselves.'".
Carry out finding responses to chat-again: try finding responses to chat-hello-harry instead.

Report giving link to chat-goodbye: instead say "'See you later, Harry.' ".
Report giving text for chat-goodbye: activate chat-again; instead say "'Later!'".

Test me with "talk to harry / 1 / 1 / 1 / i / talk to harry / 1 / 4 / 2".[/code][/spoiler]

This fixes the spacing issues.

Hope this helps.