Lag or overlap when switching between scenes

Here is a simplified version of the way I have tried to set up some scenes in a game. It uses the Questions extension, but I don’t know if that’s relevant or not to the difficulty I’m running into.

What I want to happen: the player types “x doodad,” is prompted with a question, and after answering the question, gets some kind of immediate consequence (either ending the game or changing the scene and location). It would also be nice if Scene 1 would end before Scene 2 begins. There are fair number of things in the game that depend on which scene is happening at the time, and I hadn’t really planned for overlap…not sure if it would cause problems.

What actually happens when you run the example: The consequence is not immediate–there’s an extra prompt between the question and the consequence.

What actually happens when you run the game: There’s an extra prompt between the answer and the scene change, AND the “Scene 2 is beginning” message displays before the “Scene 1 is ending” message, with the first/incorrect room description between them. (The room description appears in response to the command “look” which was typed at the extra prompt.)

Suggestions?

Example:

[code]Include Questions by Michael Callaghan.

Scene1 is a scene.
Scene1 begins when play begins.
Scene1 ends dangerously when InvestigatedTheDoodad is true.
When Scene1 ends dangerously, say “Scene 1 is now ending dangerously!”

Scene2 is a scene.
Scene2 begins when Scene1 ends dangerously.
When Scene2 begins:
Say “Scene 2 is now beginning!”;
Move the player to the Spaceship.

Scene9 is a scene.

Yard is a room.
The description of the yard is “It’s a yard!”.

A doodad is a thing in the yard.
Instead of taking the doodad, say ExamineDoodadRoutine.
Instead of examining the doodad, say ExamineDoodadRoutine.

To say ExamineDoodadRoutine:
If Scene1 is happening:
Say “Here’s a question for you.”;
Now current question is “Are you SURE you want to examine the doodad?”;
Now current question menu is { “no”, “yes” };
Ask a closed question, in menu mode;
Otherwise if Scene9 is happening:
Say “blah blah blah”.

InvestigatedTheDoodad is a truth state that varies.
InvestigatedTheDoodad is usually false.

A menu question rule (this is the DoodadChoice rule):
If the current question is “Are you SURE you want to examine the doodad?”:
If the number understood is 1:
End the story saying “You chose not to examine the doodad. How boring.”;
If the number understood is 2:
Say “You have chosen to examine the dangerous doodad! Oh no!”;
Now InvestigatedTheDoodad is true;
Exit.

Spaceship is a room.[/code]

Update:

So I’ve now tried the SCENE testing command on the game, and according to that, the two scenes in the game do not actually overlap. Apparently the first one ends, and immediately after that, the second one begins. However, I still don’t understand why the text that’s supposed to print when the second scene begins, would show up before the text that’s supposed to print when the first scene ends, or why the room description shows up between them.

Re: the example code above: adding a “stop the action” line immediately after “Now ExaminedTheDoodad is true” successfully gets rid of the extra prompt. But it also causes the game to get stuck in question mode. I haven’t been able to figure out how to get out of question mode and also skip to the end of the turn in order to activate the scene change.

Okay, here’s a potential way to deal with this. I am open to other suggestions, however, as well as explanations for why the text that is supposed to print at the beginning and end of scenes prints in the sequence that it does.

I added a “When Scene1 ends” section to turn off question mode, and added two “stop the action” lines to the menu question rule section:

[code]Include Questions by Michael Callaghan.

Scene1 is a scene.
Scene1 begins when play begins.
Scene1 ends dangerously when InvestigatedTheDoodad is true.

When Scene1 ends:
Say “Scene 1 is now ending!”;
If we are asking a question:
Now the Command Prompt is the saved prompt;
Now the Current Prompt is “”;
Now menu question mode is false;
Say “We just switched off question mode!”;
Say “Hooray!”.

When Scene1 ends dangerously:
Say “Scene 1 is now ending dangerously!”.

Scene2 is a scene.
Scene2 begins when Scene1 ends dangerously.
When Scene2 begins:
Say “Scene 2 is now beginning!”;
Move the player to the Spaceship.

Scene9 is a scene.

Yard is a room.
The description of the yard is “It’s a yard!”.

A doodad is a thing in the yard.
Instead of taking the doodad, say ExamineDoodadRoutine.
Instead of examining the doodad, say ExamineDoodadRoutine.

To say ExamineDoodadRoutine:
If Scene1 is happening:
Say “Here’s a question for you.”;
Now current question is “Are you SURE you want to examine the doodad?”;
Now current question menu is { “no”, “yes” };
Ask a closed question, in menu mode;
Otherwise if Scene9 is happening:
Say “blah blah blah”.

InvestigatedTheDoodad is a truth state that varies.
InvestigatedTheDoodad is usually false.

A menu question rule (this is the DoodadChoice rule):
If the current question is “Are you SURE you want to examine the doodad?”:
If the number understood is 1:
End the story saying “You chose not to examine the doodad. How boring.”;
Stop the action;
If the number understood is 2:
Say “You have chosen to examine the dangerous doodad! Oh no!”;
Now InvestigatedTheDoodad is true;
Stop the action;
Exit.

Spaceship is a room.[/code]

Here’s what a transcript looks like using the SCENES command. The sequence is still a bit mystifying, but maybe it won’t affect the game too much…?

[rant=Transcript]Yard
It’s a yard!

You can see a doodad here.

SCENES
Scene ‘Entire Game’ playing (for 0 mins now)
Scene ‘Scene1’ playing (for 0 mins now)
(Scene monitoring now switched on. Type “scenes off” to switch it off again.)

X DOODAD
Here’s a question for you.
Are you SURE you want to examine the doodad?
1 - no
2 - yes

Please select a number between 1 and 2 >2
You have chosen to examine the dangerous doodad! Oh no!

[Scene ‘Scene1’ ends]
[Scene ‘Scene1’ ends dangerously]
Scene 1 is now ending dangerously!
[Scene ‘Scene2’ begins]

Scene 2 is now beginning!

Spaceship
Scene 1 is now ending!
We just switched off question mode!
Hooray!

[/rant]

I think the room description is popping up because of the “move the player…” statement. Try using “now the player is in…” instead and it might solve that problem, at least.

If you don’t want the room description to print, you can write “Move the player to the Spaceship, without printing a room description.” See section 8.7 or 8.9 of Writing with Inform. I think “Now the player is in…” does print a room description.

I appreciate the suggestions. However, printing the room description of the new room after moving the player is actually what I want. What surprises me is that the moving of the player and displaying of the room description appears at that particular step in the sequence, relative to the other scene-changing activity. It seems like a symptom of overlap between the scenes.

Here’s what I mean, if anyone is still curious at this point. Here’s a better example that doesn’t require the extension:

[code]“The Spaceship and the Special Prop”

Part 1 - Scenes

Scene1 is a scene.
Scene1 begins when play begins.
Scene1 ends dangerously when InvestigatedTheDoodad is true.
When Scene1 ends:
Say “Scene 1 is now ending! Therefore, the Special Prop will now appear in the Spaceship!”;
Move the Special Prop to the Spaceship.
When Scene1 ends dangerously:
Say “Scene 1 is now ending dangerously!”.

Scene2 is a scene.
Scene2 begins when Scene1 ends dangerously.
When Scene2 begins:
Say “Scene 2 is now beginning! Therefore, the player will now move to the Spaceship!”;
Move the player to the Spaceship.

Part 2 - Rooms

Yard is a room.

A doodad is a thing in the yard.
InvestigatedTheDoodad is a truth state that varies.
InvestigatedTheDoodad is usually false.
Instead of examining the doodad:
Now InvestigatedTheDoodad is true.

Spaceship is a room. The description of the spaceship is “[if Scene1 is happening]This part of the spaceship description should print when Scene 1 is happening.[end if][if Scene2 is happening]This part of the spaceship description should print when Scene 2 is happening.[end if]”.

Special Prop is a thing. Special Prop is nowhere.

Test me with " x doodad / look".

[/code]

Given the way I’ve linked the scenes (Scene2 begins when Scene1 ends dangerously), I would expect something like this to happen when the player examines the doodad:

  1. “Scene 1 is now ending dangerously!”
  2. “Scene 1 is now ending! Therefore, the Special Prop will now appear in the Spaceship!”
  3. Special Prop gets moved to the Spaceship.
  4. “Scene 2 is now beginning! Therefore, the player will now move to the Spaceship!”
  5. Player is moved to the Spaceship, displaying the “Scene 2” segment of the Spaceship description as well as mentioning the Special Prop in the room.

What actually happens is that some of the Scene 2 stuff is happening before some of the Scene 1 stuff, like so:

  1. “Scene 1 is now ending dangerously!”
  2. “Scene 2 is now beginning! Therefore, the player will now move to the Spaceship!”
  3. Player is moved to the Spaceship, displaying the “Scene 2” segment of the Spaceship description. However, the Special Prop is not mentioned with the room description.
  4. “Scene 1 is now ending! Therefore, the Special Prop will now appear in the Spaceship!”
  5. Now the Special Prop is mentioned if you type “look.”

[rant=transcript]>x doodad
Scene 1 is now ending dangerously!

Scene 2 is now beginning! Therefore, the player will now move to the Spaceship!

Spaceship
This part of the spaceship description should print when Scene 2 is happening.

Scene 1 is now ending! Therefore, the Special Prop will now appear in the Spaceship!

look
Spaceship
This part of the spaceship description should print when Scene 2 is happening.

You can see Special Prop here.[/rant]

It makes me a bit wary of linking various things to the beginnings and endings of scenes, if I can’t assume that the first scene stuff will finish running before the second scene stuff starts running. Hopefully that makes sense. Sorry for the length.

The scene-changing mechanism is what it is. You’ve got declarations of two things happening “when Scene1 ends dangerously”, and the compiler has to pick an order. I don’t know the entire algorithm (though it’s not picking randomly).

In this case, the declaration “Scene2 begins when Scene1 ends dangerously” means that the scene-changing mechanism starts up Scene2 during one of the Scene1-end rules. It’s not the last Scene1-end rule, is what you’re seeing.

It looks to me like you’re butting up against something like non-bug 1147, where the

If, giving the rules appropriate names, we write:

The scene 1 ending rule is listed before the scene 1 ending dangerously rule in the when scene ends rulebook.

we get:

and if we write:

The scene 1 ending rule is listed before the scene 1 ending dangerously rule in the when scene1 ends rulebook.

we get:

which suggests that the “scene 1 ending dangerously rule” is in the “when scene ends” rulebook and the “scene 1 ending rule” is in the “when scene1 ends” rulebook. (Sorry for the ponderousness of this, but I couldn’t figure out where to find these rules in the Index. The “scene 1 ending rule” doesn’t show up anywhere in the Scenes tab of the Index.) Per that bug report, the general “when scene ends” rulebook always runs before the “when scene1 ends” rulebook, so there’s no way to reverse the order in which those rules fire. I’m not sure why “when scene1 ends dangerously” winds up in the “when scene ends” rulebook, though, if that’s what’s happening.

Thanks for your help. I’m still fuzzy on this (which I blame on my being relatively new to Inform, not on your explanations), but basically what I am taking from this (feel free to let me know if I am way off) is that I can’t necessarily expect “When Scene1 ends dangerously” stuff and “When Scene1 ends” stuff to happen one right after the other. (Possibly because they are in two different rulebooks, or possibly because I have too many “When Scene1 ends dangerously” declarations, or possibly something else altogether, but the main thing is that it doesn’t necessarily work that way.)

However, I can (I think?) reasonably expect “When Scene2 begins” stuff to closely follow “When Scene1 ends dangerously” stuff, seeing as they are explicitly linked together by the line “Scene2 begins when Scene1 ends dangerously.”

So it seems I should avoid any super-time-sensitive maneuvers of props, values, etc. in the “When scene1 ends” declaration. I could put them in the “when Scene1 ends dangerously” declaration (as well as any other applicable “When Scene1 ends adverbly” declarations) instead, or in the “when scene2 begins” declaration.

Anyway, you’ve already put a lot of time into answering my questions, so I don’t want to keep dragging this out. Thank you for your help!