[I6] Parsing Strings and Numbers

After all these years (and coming from a C++ background) I still haven’t understood in detail how Inform 6 parses strings. Following problem: In the game, at one time I want the player to enter a number. Just a number, nothing else. My approach (don’t laugh) is to use BeforeParsing. I’m fiddling around with ParseNumber and NextWord but to no avail. How the heck do I check if the player’s input is a number between 1 and 100?

Anyone? Basically I want to ask the player at the beginning of the game how old she is.

I think I may try to do that in the weekend, when there’s time. There’s an example in the manual; assuming you’ve tried that already, I’m gonna try and see what’s nontrivial about it.

It’s possible to define an action, and associate “[any number]” with it as a command.

The Maths Room is a room. Digital screen is a thing in the Maths Room. "The large digital screen in the corner displays [current tally]."
Current tally is a number variable.

Tallying is an action applying to one number. Understand "[any number]" as tallying when the location is the Maths Room.

Carry out tallying a number (called N):
	 now current tally is current tally plus N.
	
Report tallying a number (called N):
	let W be "[N in words]";
	say "'[W in sentence case]', you announce loudly. The screen wavers for a second, then triumphantly flashes up [current tally]."

But for your problem, you’d be better off using an “After reading a command” rule. Something like this:

Age is a number variable.
Age Room is a room.

When play begins:
	now the command prompt is "What is your age? >";
	
After reading a command when the command prompt is "What is your age? >":
	if the player's command matches "[any number]":
		now age is the number understood;
		say "You are [age] years old.";
		now the command prompt is ">";
	otherwise:
		say "I need a number.";
	reject the player's command.

They’re asking about I6, not I7 though…

Oops! I even noticed that on Sunday, which is why I didn’t reply then.

…I got nothing, sorry. In this case it went past nontrivial for me and straight into non-doable territory.