"Reading" Player Input

Hi folks–

I’m as newb as they get with Inform, so apologies in advance for stupidity.

I am trying to design an IF for my students to help them learn grammar. To do so, I want them to type (not choose from a list) a sentence correctly, and then check to see if they got it right.

So here’s some pseudo-code to show what I want:

1 Say, “Correct the comma splices in the following example: ‘I came, I saw, I conquered.’”
2 If player types,
3 “I came. I saw. I conquered.”, or
4 “I came; I saw; I conquered.”, or
5 “I came, I saw, and I conquered.”, or
6 [a few more versions];
7 Say, “Correct!” and raise the player’s score by one point;
8 Else, say “Sorry, that’s incorrect.”

I’m pretty sure this is possible, but I missed it in the documentation, and a forum search (probably because of weak search-fu) yielded nothing. Any help would be greatly appreciated; paste-able code will endear me to you forever. Thanks in advance!

There are a few ways to do this. Probably the easiest would be to use an “After reading a command” rule, like so:

After reading a command: if the player's command matches <CORRECT ANSWER ONE> or the player's command matches <CORRECT ANSWER TWO> or the player's command matches <CORRECT ANSWER THREE>: say "Correct."; otherwise: say "Sorry, that's not correct."

Though, if I were you, I would try to learn the basics of I7. It will make things a lot easier than having to come here every time you want some new feature - and, more importantly, you won’t have to wait for answers.

EDIT: Note that this code will run for EVERY command typed. That might be a problem. If you want to have multiple lessons in one “game”, you’ll need to use a variable to keep track of the current lesson, and only run the appropriate rules.

Also, I didn’t provide a way for you to display your question, come to think of it. Just use an “Every turn” rule.

There’s an extension called Questions that can handle the question-asking machinery for you, and allow you to link questions together into a script.

–Erik

Thanks to both of you for your replies. I thought I would try writing my own code (as opposed to using the Questions extension) so as to learn Inform better (following your advice, Bio). The code I have created now is giving me a “translating the source” error, where it says that there is a bug in the program that does not allow it to compile. I am fairly certain this is not the case, but that I am doing something wrong. Here is my code for trying to match the player’s text to a predetermined answer:

A person can be wary or relaxed. A person is usually relaxed.

To decide whether accepting answers:
	if the scene is Monday afternoon, yes;
	no.
	
After reading a command when accepting answers:
	if the player's command matches "spell":
		award 1 point;
		say "[Text that isn't important to the code].";
		now the player is wary;
		reject the player's command;
	otherwise:
		award -1 point;
		say "[Text that isn't important to the code].";
		now the player is wary;
		reject the player's command.

Monday afternoon ends when the player is wary. Quiz time begins when Monday afternoon ends.

Anyone see anything wrong with this? Much obliged!

P.S. Here is the error message I get from Inform:

I believe the problem is with the “if the scene is Monday afternoon, yes;” line. You can have several scenes running at the same time so you can’t ask what is “the scene”. The correct phrasing is “if Monday afternoon is happening.”

Thanks Juhana! This is definitely closer: no more unexplained compile failure, at any rate. I guess correct phrasing is “going on” rather than “happening,” but now I am getting this error:

Here is my code:

A person can be wary or relaxed. A person is usually relaxed.
	
After reading a command if Monday afternoon is going on:
	if player's command matches "spell":
		award 1 point; 
		say "[Words words words].'";
	          	now the player is wary;
	          	reject the player's command;

Thanks much for the help, and sorry to be so hopeless. Just think of the students you’ll be helping learn grammar! :slight_smile:

That “if” should be “when”.