Table Unstable! (Should I relabel?)

So I am in the throes of trying to write a scene where a professor (of magic) asks students quiz questions. I am trying to use a table to cycle through the questions. I’ve gotten very close–parts of the code have compiled and worked–but I haven’t been able to make the code do all of the following:

  1. Ask questions one at a time.
  2. Read the player’s input.
  3. Compare the player’s input to an answer.
  4. Either reward or punish the player for being right or wrong (respectively).
  5. Move on to the next question, after a bit of colorful dialogue.

So here, in simplified form for easier reading, is my code. It does not currently compile, but I think the error message it is giving me about misaligning my “ifs” and “otherwises” isn’t the issue. Please try not to faint at the code’s inelegance:


The Dueling Pit is a room. "Scorch marks and dried blood adorn the Dueling Pit. Does the board of education know about this place?".

Professor Dimflame is a man in the Dueling Pit. "Professor Dimflame: the bane of all freshman at Margram Academy.".

Tyra is a woman in the Dueling Pit. "Your opponent for today is Tyra. She looks like she wants to set you on fire.".

Every turn during Monday Testing:
	 if the score is zero:
		say "I think you should study sentence objects a little more before you try to duel Tyra again. [paragraph break] GAME OVER";
		end the game in death.

When Monday Testing begins: 
	say "Professor Dimflame, his face somewhere between annoyed and amused, says, 'Well, for better or worse, it[']s time to begin the duel. Perhaps I should give you two football helmets to wear? Oh, but that wouldn't be nearly as funny. What was I thinking? Okay, [player's forename in title case], you're up. Here is your next question.'[paragraph break] Dimflame gives you a mean squint, then asks you,[paragraph break][Query entry in row one of the Table of Quiz Queries]'":
		if the player's command matches "[topic entry in row one of the Table of Quiz Queries]":
			award 1 point;
			consider the custom notify score changes rule;
			say "[Correct entry][paragraph break] Ready for the next one?";
			change the current challenge to the current challenge + 1;
			reject the player's command;
		otherwise:
			award -1 point;
			consider the custom notify score changes rule;
			say "[Incorrect entry][paragraph break] You'd better start getting more answers correct!";
			change the current challenge to the current challenge + 1;
			reject the player's command;
	consider the quiz problem rule. 
	
The current challenge is a number that varies. The current challenge is 1.

Before doing something during Monday Testing:
	say "Ready for the next one?";
	consider the quiz problem rule;
	reject the player's command.

This is the quiz problem rule:
	repeat through the Table of Quiz Queries:
		if the number entry is the current challenge: 
			say "[query entry]";
			consider the check answer rule;
		otherwise:	
			say "The quiz is over.".
			
This is the check answer rule:
	let N be the value of the current challenge;
	if the player's command matches the topic entry in row N of the Table of Quiz Queries:
		award 1 point;
		consider the custom notify score changes rule;
		say "[Correct entry][paragraph break]";
		change the current challenge to the current challenge + 1;
		reject the player's command;
		rule succeeds;
	otherwise:
		award -1 point;
		consider the custom notify score changes rule;
		say "[Incorrect entry][paragraph break]";
		change the current challenge to the current challenge + 1;
		reject the player's command;
		rule succeeds. 
	
Table of Quiz Queries
Number	Query	                                                                Topic	Correct	     Incorrect
1	        "What is the object of line five of the poem?"	        "it"	        "Correct!"	     "Wrong."
2	        "What is the object of line six of the poem?"	        "wand"	"Right!"	     "Quite wrong."
3	        "What is the object of line eight of the poem?"	"ground"	"Good!"	     "Wrong wrong wrong."
4	        "What is the object of line ten of the poem?"	        "prince"	"Well done!"  "Nope."
5	        "What is the object of line eleven of the poem?"	"none"	"Excellent!"   "Just plain wrong!"
--	--	--	--	--

N.B. The table is correct in my code, but it is almost assuredly misaligned as pasted above.

Any/all help is greatly appreciated. I was thinking, as a small but earnest thank-you, to offer those who help with the game a cameo role in “Margram” (that’s the IF I am working on) as one of the wizard-professors. If you have helped or are helping me now, let me know if you would like to be immortalized in the game! :slight_smile:

When Monday Testing begins: 
	say "Professor Dimflame, his face somewhere between annoyed and amused, says, 'Well, for better or worse, it[']s time to begin the duel. Perhaps I should give you two football helmets to wear? Oh, but that wouldn't be nearly as funny. What was I thinking? Okay, [player's forename in title case], you're up. Here is your next question.'[paragraph break] Dimflame gives you a mean squint, then asks you,[paragraph break][Query entry in row one of the Table of Quiz Queries]'":		

That should be a semicolon, not a colon. Try fixing that and see if other problems pop up … I haven’t looked through the whole thing.

–JA

Thanks Jim–

I’ve been fooling with semi-colons and colons all day. I settled on the structure in this post because it gave me the fewest errors (not that that means anything–either code compiles or it doesn’t, right?). But when I made your change and then fixed the alignment of the tab-structure, here is the list of errors I got:

I’m putting this here in case it helps someone smarter than me decipher just how many mistakes I’ve made and how to fix them.

Coding is hard. :cry:

I hate the syntax for accessing Tables. It’s just horrible. I spent a few minutes on this, and got nowhere. All I can say is, read the manual, and good luck!

A couple of general points before my suggested code:

  1. The stuff about “reject the player’s command” is usually reserved from meddling with the command before parsing, in the “After reading a command” phase.

However, you probably don’t want to use “After reading a command” for this, because in doing so, you’re bypassing normal command and action processing. What that means is that when you “reject the player’s command”, Inform skips any attempt to do its normal per-turn rules, and you wind up never firing the every turn rules and before doing… rules you’ve created. So even if you get the topic lookup working right, you’ll find your quiz not scoring itself properly.

What I suggest is making a legitimate verb to handle this, that – during the duration of the quiz only – treats all otherwise unidentifiable text as an attempt to answer the quiz.

  1. You don’t need to enumerate the rows of your table separately, because they’re already accessible this way: you can say “row 2 of the Table of Quiz Queries” and have it select accordingly.

  2. “[Query entry in row one of the Table of Quiz Queries]” goes awry because of the word “entry”, which should not be there. (I’ve approached this differently anyhow, in the code below.)

[code]
The Dueling Pit is a room. “Scorch marks and dried blood adorn the Dueling Pit. Does the board of education know about this place?”.

Professor Dimflame is a man in the Dueling Pit. “Professor Dimflame: the bane of all freshman at Margram Academy.”.

Tyra is a woman in the Dueling Pit. “Your opponent for today is Tyra. She looks like she wants to set you on fire.”.

The player’s forename is some indexed text that varies. The player’s forename is “Jill”.

The current challenge is a number that varies. The current challenge is 1.

Monday Testing is a scene. Monday Testing begins when we have looked.

Every turn during Monday Testing:
if the score is less than zero:
say “I think you should study sentence objects a little more before you try to duel Tyra again. [paragraph break] GAME OVER”;
end the game in death;
otherwise:
choose row current challenge in the Table of Quiz Queries;
say “[query entry]”.

Before doing something other than quiz-guessing during Monday Testing:
say “‘Mind on the quiz!’ snaps Dimflame.” instead.

Understand the commands “say” and “answer” as something new.

Understand “[text]” or “say [text]” or “answer [text]” as quiz-guessing when Monday Testing is happening. quiz-guessing is an action applying to one topic.

Carry out quiz-guessing:
choose row current challenge in the Table of Quiz Queries;
if the topic understood matches the topic entry:
award 1 point;
say “’[Correct entry]’[paragraph break]”;
change the current challenge to the current challenge + 1;
otherwise if the topic understood is a topic listed in the Table of Quiz Queries:
say “‘You may be thinking of the wrong line,’ says Dimflame, as a hint.” instead;
otherwise:
choose row current challenge in the Table of Quiz Queries;
award -1 point;
say “’[Incorrect entry]’[paragraph break]”;
change the current challenge to the current challenge + 1;

When Monday Testing begins:
say “Professor Dimflame, his face somewhere between annoyed and amused, says, ‘Well, for better or worse, it[’]s time to begin the duel. Perhaps I should give you two football helmets to wear? Oh, but that wouldn’t be nearly as funny. What was I thinking? Okay, [player’s forename in title case], you’re up. Here is your next question.’”.

Monday Testing ends when the number of filled rows in the Table of Quiz Queries is less than current challenge.

When Monday Testing ends:
if score is 5:
say “‘Well,’ says Dimflame, beaming, ‘You’ve certainly proven yourself today, [player’s forename in Title Case]!’”;
otherwise if score is greater than 2:
say “‘Not perfect, but you’re making progress,’ Dimflame says grudgingly.”;
otherwise:
say “‘An uninspiring performance, but at least the quiz is now over,’ grumbles DImflame. ‘We can be grateful for small favors.’”

Table of Quiz Queries
Query Topic Correct Incorrect
“What is the object of line five of the poem?” “it” “Correct!” “Wrong.”
“What is the object of line six of the poem?” “wand” “Right!” “Quite wrong.”
“What is the object of line eight of the poem?” “ground” “Good!” “Wrong wrong wrong.”
“What is the object of line ten of the poem?” “prince” “Well done!” “Nope.”
“What is the object of line eleven of the poem?” “none” “Excellent!” “Just plain wrong!”
– -- – -- [/code]

I guess it’s no surprise that your code compiled beautifully and did everything I hoped it would, Emily. Thank you so much for taking the time to fix my many errors.

Thanks, too, for the explanation–I was pretty egregiously misusing the “reject the player’s command” function.

On another note, Emily, would you like to be a professor in the Margram Academy of Magic? Jim, that goes for you too (and for the other folks who have helped me in other threads; I’ll be contacting you separately). I’ll be presenting Margram at a National Endowment for the Humanities Institute this summer, and I would, with your permission, like to memorialize you in-game, to complement the praise I will heap on the intfiction community in general, and you all in specific, for your patience and constant help. Help isn’t even the right word–you all have written everything but the most basic parts of the code for me. Thanks again, everyone.