Continuing after a Yes or No

I want to have an NPC in the game ask the player character if he wants to do something. It looks as if yesOrNo() handles this pretty well:

                    if (yesOrNo()) {
                        "\"Great! Here we go.\" ";
                        //Do the stuff
                    else {
                        "\"OK, I'll ask you again later.\" " ;

But in the case where the player types neither yes nor no, but instead enters a totally unrelated game command, like >jump or >look, I’d like the game to be able to say, “OK, I’ll ask you again later,” but then go on to execute the player’s command. Any ideas?

I’ve never done this, but it looks as if you need to use inputManager.getInputLine(nil, nil), as described in the Tech Manual, in the “Some Common Input/Output Issues” article. Once you have the actual input line that the player typed, I’m sure there’s a way to check it to see whether the string fails to match ‘y’, ‘n’, ‘yes’, or ‘no’. Possibly you’ll need to convert it to lower-case before testing it.

The yesOrNo() function is probably meant for little different situations, than normal course of the story. I would imagine something like “Are you sure you want to overwrite the save file?” where the player is expected to reply only yes or no, when the player is controlling the software and not living the story.

I would strongly suggest modelling the yes/no situation in the story by YesTopic and NoTopic in conversation node. Look to chapter 14.7 in Learning TADS 3, especially on complex example starting on page 237 at the bottom of the page. This example is about insisting on an answer, but you can modify it easily enough not to. Just don’t do <.convstay> on DefaultAnyTopic and allow ending a conversation.

But if you wish, you can take the source of yesOrNo() (Library Reference Manual - all symbols - yesOrNo - click on the link leading to the source code) and when it is not yes or no, just: throw new ReplacementCommandStringException(‘some command’, gIssuingActor, gActor); where ‘some command’ would be replaced by the str variable.

You can write your own function for this. The yesOrNo() function is defined in lib/adv3/en_us/en_us.t:

yesOrNo() { "<.commandnone>"; local str = inputManager.getInputLine(nil, nil); "<.commandmid>"; return rexMatch('<space>*[yY]', str) != nil; }

It simply returns true if you enter something that begins with “y” or “Y”. You can write a new function, say yesOrNoOrOther(), that returns 1 on yes, 2 on no and 3 on anything else:

yesOrNoOrOther() { "<.commandnone>"; local str = inputManager.getInputLine(nil, nil); "<.commandmid>"; if (rexMatch('<space>*[yY]', str)) return 1; if (rexMatch('<space>*[nN]', str)) return 2; return 3; }

Didn’t test it, but should work.

Your code would use the function like this:

switch (yesOrNoOrOther()) {
case 1:
"“Great! Here we go.” ";
//Do the stuff

case 2:
    "\"OK, let's not then.\" ";

  "\"OK, I'll ask you again later.\" " ;


That is the quick & dirty way to do it. If you want to really do this 100% properly, you would need to check if a turn has passed before deciding whether the player answered the question or not. I wrote a small module in the past (it’s from 2003) for this. You can use that if you want and adapt it to your own needs. I’ll attach it to this post.
ncYesNo.txt (5.05 KB)