Works in one place but not in another

Thanks so far, everyone, for all the help I’ve received on the forums. Slowly, but surely–but slowly!–I’m catching on to Inform.

My problem this time is that things that work perfectly in one part of the game fail to activate in another, even though the code compiles. I have two examples.

  1. I stole a custom notify score rule from some good soul on these boards. Works great–except, when I changed the scene, it seemed not to notify players when their scores rises anymore. Is there any reason a rule would not be global, even though I wrote in nothing to make the rule scene-specific?

  2. This one is really frustrating. Maybe it’s just better to show you some simplified version of it:

[code]A person can be relaxed, wary or ready. A person is usually relaxed.

The schoolhouse is a room.

The teacher is a woman in the schoolhouse. Understand “the teacher” and “teacher” as the teacher. The description of the teacher is “This teacher loves to give tests.”

After examining the teacher, award 5 points.

Monday Morning is a scene. Monday Afternoon is a scene. Monday Testing is a scene. Monday Morning begins when play begins.

Monday Afternoon begins when Monday Morning ends. Monday Morning ends when the score is 5.

Monday Testing begins when Monday Afternoon ends. Monday Afternoon ends when the player is ready.

When Monday Afternoon begins:
now the player is wary;
say “The teacher asks you, ‘What is the object of the sentence [’]Wizards cast spells?[’]’”.

After reading a command while the player is wary:
if player’s command matches “spells”:
say “Correct!”;
now the player is ready;
reject the player’s command;
otherwise:
award -1 point;
say “Wrong!”;
reject the player’s command.

When Monday Testing begins, say “Okay, it looks like you’re ready for your test. Good luck!”
[/code]

Test with “x teacher”, “spells”.

Is there any reason why the scene does not progress to Monday Testing? Thanks in advance for your help!

My guess is that it’s something to do with the “After reading a command” rules – they don’t seem to invoke some of turn sequence rules (or something like that). For instance, I can’t end the game within an “After reading a command.” So my guess is that you can’t make a scene end within an “After reading a command” rule either. Have I mentioned that this is a guess? It’s a guess.

One thing to note is that in your code fragment, the scene changes as soon as you enter another command – try “x her/spells/ look.” That’s pretty similar to what I was getting.

You may be able to accomplish what you want with a [text] token, thus:

[code]A person can be relaxed, wary or ready. A person is usually relaxed.

The schoolhouse is a room.

The teacher is a woman in the schoolhouse. Understand “the teacher” and “teacher” as the teacher. The description of the teacher is “This teacher loves to give tests.”

After examining the teacher, award 5 points.

Monday Morning is a scene. Monday Afternoon is a scene. Monday Testing is a scene. Monday Morning begins when play begins.

Monday Afternoon begins when Monday Morning ends. Monday Morning ends when the score is 5.

Monday Testing begins when Monday Afternoon ends. Monday Afternoon ends when the player is ready.

When Monday Afternoon begins:
now the player is wary;
say “The teacher asks you, ‘What is the object of the sentence [’]Wizards cast spells?[’]’”.

Question-answering is an action applying to one topic. Understand “[text]” as question-answering while the player is wary.
Instead of question-answering:
say “I didn’t ask you a question; you’ll have to type a command.” [I don’t think this actually ever gets invoked; I put it in because I wasn’t actually expecting “Understand… while the player is wary” to work.]
Instead of question-answering while the player is wary:
if the topic understood matches “spells”:
say “Correct!”;
now the player is ready;
otherwise:
award -1 point;
say “Wrong!”.

When Monday Testing begins, say “Okay, it looks like you’re ready for your test. Good luck!”[/code]

This actually gives me an idea for how I might be able to fix my game that tried to use “After reading a command” rules.

matt

I think that’s correct. When you reject the player’s command, you skip most of the turn sequence rules: no action is generated, scenes don’t change, time doesn’t move forward, “every turn” rules don’t run, light isn’t adjusted, score change notifications don’t appear, etc.

If you add “consider the scene changing rules;” before “reject the player’s command;” then the scene will change as expected. If you want any of those other things to happen too, look at the turn sequence rulebook (under “The top level” in the Rules index) to see which rules you need.

Vaporware, your “consider [whatever] rule” advice fixed both of my immediate problems; everything is working now. And Matt K, your “question-answering” is more flexible and useful than what I had done, so I will probably rewrite my code to reflect your method. A tremendous thank you to both of you.

vw, which set of rules would I consider in order to make sure that the game ends when I want it to? I looked back at the original discussion ([url]https://intfiction.org/t/code-to-limit-verb-guesses-with-a-bug/837/1]) where an issue like this came up for me, and my original attempt involved printing a parser error; the solution Erik came up with did involve “After reading a command,” which I think worked because instead of rejecting the command it invoked another action, which wasn’t going on in my other game.

Invoking an action is probably the easiest way to get what you want. Invent a question-answering action, and “try” it. Or use the regular “Understand” declarations to accept “spells” as a verb – you can do this conditionally.

What you’re doing now is trying to emulate a complicated bit of the parser (carrying out an action) inside a smaller piece (the “after reading a command” phase) and it will be a bit of work to make that work perfectly.