How to do numerical inputs

I originally wrote this in the general forum, but discovered that I should put it here instead:

I have a part in the game I’m writing where the player is required to enter a specific number. How would I write a rule for this? I’m using I7.

What more exactly is that you want to do?
If you want the game to react to a command that only consists of a specific number (and no other text) at just a specific point in the story, you can set some variable to indicate that this point in the story is reached and then catch the input with an after reading a command rule:

Time to guess a number is a truth state that varies. After examining the Hastings quizz: now the time to guess a number is true. After reading a command when the time to guess a number is true: if the player's command matches "1066": [or whatever number is the right one] say "You just won a brand new matchbox!"; now the player carries the matchbox; otherwise: say "Sorry, that was not the correct answer."; now the time to guess a number is false.

(A variant on this theme (using the text of the command prompt as variable) for opening a door with a password can be found in this post in an earlier thread on the forum: [url]])

Look at “Down in Oodville” in the help. Example #293.


Felix: Your external example worked perfectly. Thank you so much.

Also, if anyone will listen, I know this sounds stupid, but how do you define responses to “talk to [person]”?

“talk to [someone]” isn’t programmed in by default, so you can program it in the way you’d create any other command and action. See section 12.7 and the following sections., and maybe chapter 16 on understanding (though you shouldn’t need that much).

Exactly how to do it seems like it probably depends on the complexity of the behavior you’re trying to include. If you just have a few NPCs with stock responses, you can use a few rules like this:

Instead of talking to the peasant: say "The peasant sighs and says, 'Times are tough!'"

(Assuming your action is “talking to.”) Ex. 168 (“Cheese-Makers”) shows you how you can vary this up using scenes and a bit of other stuff to vary some of the responses. For some other purposes you might want to use a table.

Going sideways in this topic - I am interested in catching a range of integer numbers.

As an example - if the player types an integer number between 0 and 300 at the regular parser, I’d like to intercept that and call it ‘counting’. I don’t need to know what the number was after the match, only that a matching number was typed.

I understand Felix’s example about checking the player’s input, but how might I check for a range? And also… would adding such code mess up the work of extensions like Numbered Disambiguation Choices?

You could just make an action that applies to a number and use normal check rules to make sure the player stays within range. This doesn’t discard the input if it’s outside the range, but I assume you would want to have a customized error message anyway.

[code]Counting is an action applying to one number.
Understand “[number]” as counting.

Check counting:
if the number understood is less than 0 or the number understood is more than 300:
say “Number out of range.” instead.
With nice round numbers like 300 you can use some regular expression magic if you want to expand Felix’s code:

After reading a command: if the player's command matches the regular expression "^<1-2>?\d?\d$" or the player's command matches "300": say "Number between 0 and 300!"; reject the player's command.

It might, but it’s likely that those extensions parse numerical input in such an early phase that there won’t be problems, or if you use the after reading a command method you can move the rules around so that the extensions get priority. On the other hand the extensions might mess up the counting action if they reserve numerical input for themselves at all times.

Thanks Juhana. I found out that just adding the [number] command worked, and happily, it also did not interfere at all with the working of Numbered Disambiguation.

There was a side effect, though. Previously when you typed a word the game didn’t recognise (or nonsense), it would reply with library message “I don’t recognise that verb.”

After I added the [number] command (the first of its kind in the game), the same circumstances would now reach for a different library message: “I didn’t understand that sentence.”

If I take it away again, those circumstances go back to the verb message.

I had a custom response set up under “don’t recognise that verb”, but since I can’t imagine a circumstance where the verb line won’t make sense when the game was otherwise going to say “I didn’t understand that sentence” (I can’t remember if in all my testing the game has ever said the latter…) I just replaced the sentence library message with the verb one.