'end the story finally' not ending story

Hey, I’m trying to create a password entry scheme that acts as a win condition for a text adventure, and am using the code posted in this thread - https://intfiction.org/t/i-just-want-to-create-a-door-with-a-password-answered/2273/4

You can see in the code posted below that when the player enters the correct password I use ‘end story finally’. However, when I test it the results aren’t what I expect. When the correct password is entered, it simply prompts another “Enter password >”. However, when I use the ‘quit’ command anytime after entering the correct password it displays win followed the normal end story stuff.

Can someone point me in the right direction? I would like for the game to immediately end when the player enters the correct password.

Thanks.

After examining the laptop:
	now the command prompt is "Enter password >";
	continue the action.

After reading a command when the command prompt is "Enter password >":
	if the player's command matches "i choose you" or the player's command matches "I choose you":
		end the story finally saying "win";
	otherwise:
		say "Password denied.";
		now the command prompt is "Would you like to try again? (Yes or No) >";
	reject the player's command.

After reading a command when the command prompt is "Would you like to try again? (Yes or No) >":
	if the player's command matches "Yes" or the player's command matches "yes":
		now the command prompt is "Enter password >";
		say line break;
		say run paragraph on;
		reject the player's command;
	if the player's command matches "No" or the player's command matches "no":
		now the command prompt is ">";
		say line break;
		say run paragraph on;
		reject the player's command;
	otherwise:
		say line break;
		say run paragraph on;
		reject the player's command.

I’m not perfectly sure why the story isn’t ended until the next turn, but I think it may be that these after reading a command rules stop any command at all from being processed and therefore it doesn’t count as a turn at all (at least the turn count on the status line does not increase), and Inform doesn’t check if the story has ended until after a turn is over (or perhaps just before the next turn starts), so the game doesn’t know to end the story until after a player’s command has actually been accepted and the turn is eventually really over.

The only way round it I could think of was to manually invoke the shutdown rules. There might be more elegant ways to do it. (I also added a line to increment the turn count. That’s only for show, though. The code would work without it. In particular it does NOT make Inform internally consider the turn as over; it only increases the turn count variable by 1.)

After reading a command when the command prompt is "Enter password >":
	increment the turn count;
	if the player's command matches "i choose you" or the player's command matches "I choose you":
		end the story finally saying "win";
		follow the shutdown rules;
	otherwise:
		say "Password denied.";
		now the command prompt is "Would you like to try again? (Yes or No) >".

(Besides, you should probably add to the conditions in the other after reading a command rule: if the player's command matches "Yes" or the player's command matches "yes" or the player's command matches "Y" or the player's command matches "y": and if the player's command matches "No" or the player's command matches "no" or the player's command matches "N" or the player's command matches "n": .)

That’s correct. Rejecting the command means short-circuiting the input loop; it jumps right back to the input prompt. Running the shutdown rules manually is a reasonable choice here. You’re essentially bypassing the entire parser, so you have to take over some of its duties.

Another alternative would be to not reject the command in this case!

By the way, you don’t have to check for upper and lower-case inputs in this code. The player’s command is lower-cased before it reaches the “reading a command” activity.

Thanks Felix and zarf, using ‘follow the shutdown rules’ immediately after ending the story worked perfectly. The only modification I made was to change this…

After reading a command when the command prompt is "Enter password >":
	if the player's command matches "i choose you" or the player's command matches "I choose you":
		end the story finally saying "win";
	otherwise:

into this

After reading a command when the command prompt is "Enter password >":
	if the player's command matches "i choose you" or the player's command matches "I choose you":
		end the story finally saying "win";
		follow the shutdown rules;
	otherwise: