I just want to create a door with a password (ANSWERED!)

#1

Firstly off, please take pity on me. - I am very new to Inform7 (I just started my story last week) I have been cruising along, with a few tiny bumps in the road… but this recent one just baffles me!

I want to create a door which when examined opens an interface to give the password. The password being text that the user enters. (let’s say “giggity”) I have tried a few different approaches. I have been at this for 2 days now. Can anyone please help me out?
Here is my most recent try (which includes “Questions” by Micheal Callaghan, but I have obviously butchered it - as it throws out errors-galore):

[code][size=85]A text question rule:
if the current question is “Can you picture the password?”:
if text understood is giggity:
say, “BUZZ You have unlocked the security door.”;
now the security terminal is unlocked;
exit;
otherwise:
exit;
otherwise:
exit.

A yes/no question rule (this is the confirm answers rule):
if the current question is “Would you like to try again? (Yes or No)”:
if the decision understood is yes:
examine security terminal;
otherwise:
say “Goodbye.”;
exit;
otherwise:
exit.

Instead of inspecting security terminal:
now the current question is “Can you picture the password?”;
now current prompt is “Please enter the password now. >”;
now punctuation removal is true;
ask a closed question, in text mode;
now the current question is “Would you like to try again? (Yes or No)”;
ask a closed question, in yes/no mode.[/size][/code]
I did consider making the security door the door and security terminal a person, who can ask for the password using the [topic] table. I do not know if a dialog can trigger an action though(like ‘now the security door is unlocked.’). Plus, I haven’t played around with adding characters yet and don’t really know what I’m doing at all there.

#2

Props on the Family Guy reference, if that’s what it was. My favorite show of all time.

Otherwise, I can’t help you. Sorry.

#3

Yeah, I was watching it earlier today and it was the first thing that popped into my head. :wink:

(Felix Larsson) #4

Here’s a way:

The description of the security terminal is "Can you picture the password?"
After examining the security terminal:
	now the command prompt is "Please enter the password now. >";
	continue the action.
	
After reading a command when the command prompt is "Please enter the password now. >":
	increment the turn count;
	if the player's command matches "giggity": 
		now the security door is unlocked;
		say "**BUZZ**  You have unlocked the security door.";
		now the command prompt is ">";
	otherwise:
		say "The security door remains closed.";
		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 "y": 
		now the command prompt is "Please enter the password now. >";
		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 "n": 
		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.
'end the story finally' not ending story
Making a passcode to unlock an object (Inform 7)
How to do numerical inputs
#5

Thank you SO much for your time and for trying to help!
That looks similar to my first try, but i have never used “run paragraph on” before. What does that do?

Also it’s still giving me errors (I just copied and pasted, so that I wouldn’t mess up your code):

[code]Problem. The phrase or rule definition ‘After reading a command when the command prompt is “Please enter the password now. >”’ is written using the ‘colon and indentation’ syntax for its 'if’s, 'repeat’s and 'while’s, where blocks of phrases grouped together are indented one tab step inward from the ‘if …:’ or similar phrase to which they belong. But the tabs here seem to be misaligned, and I can’t determine the structure. The first phrase going awry in the definition seems to be ‘if the player’s command matches “Keep” or the player’s command matches “keep”’ , in case that helps.

This sometimes happens even when the code looks about right, to the eye, if rows of spaces have been used to indent phrases instead of tabs.[/code]
It is giving me the same error for the first line in the next set also ‘After reading a command when the command prompt is “Would you like to try again? (Yes or No) >”:’
Perhaps there is some extension that you usually include that makes this work? If so, which one?

#6

Ah, you’re being caught by the forum trick. The problem with copying and pasting from the forum is that if you copy from a post, the tabs have all been converted to spaces, and Inform really requires them to be tabs. One way to quickly work around that is to make as if to reply to the post containing the code (so, hit the “quote” button), then copy the code from within the reply-to text box, where the tabs will be magically restored to how the original poster typed them in. Of course, if the original poster typed them in as spaces, you’ll still need to convert them to tabs by hand.

#7

Ok, I figured it out - my copy and paste job reads your code as having 3 spaces instead of a tab. I replaced all of the spacing with tabs and it worked PERFECTLY!!

THANK YOU Felix!! :smiley:

(thank you Trove - you were replying just as i was! That certainly beats the way I did it! I will keep that in mind for the future.)

#8

This happens so often that maybe it would be a good idea to make a post with general instructions and make it sticky?

(Felix Larsson) #9

You need to print a line break (or paragraph break) after the player has answered the question or there will be no blank line between the line with the answer and the new command prompt that follows the answer.
However, I found when testing the code, that (for some I6 reason, I think) the game would then print TWO blank lines between the lines rather than one.
This happens every now and then in Inform 7, and “run paragraph on” prevents it. It stops the next paragraph from beginning on a new line, and runs it immediately on as a single paragraph with the preceeding one (or something).

Inform 7: How to setup 'Entering Secret Codes'
#10

Thank you again Felix, you have been very helpful!

#11

Hi Felix.

How easy would it be to add a ‘timer’ to your example.

What I am trying to do is something similar to the above but have it time limited to a few moves as in turning off a burglar alarm when entering a house. If you do not enter the correct ‘code’ in say 10 moves then the police arrive and it’s game over.

Any tips appreciated.

Cheers.

#12

I think it’s as simple as this:

Every turn when the alarm has been switched on for at least 10 minutes and the location is in the Expensive Mansion: say "The police arrive."; end the story saying "You go to jail.";