making a key pad

Hi, I am very new to IF and IF programming. And by very new I mean I played my first IF game last week which was ZORK and that was only because it is playable in the new Call of Duty video game. Well I became very interested and have played some simple games and now have decided that I want to start writing IF. I have decided to write a small game to get my self acclimated with the Inform programming language.

My game is based around my house and the player has to escape the house. I figured this was an easy way to help me create rooms and things that are in those rooms because I could base it all off of my house. Well there are obviously some things that I have made different but that’s not really why I am here.

I am trying to make a keypad that opens a door. I would like the player to say something like examine keypad. This will tell them how to enter the code. Then they will enter a code and if its the right code then the door becomes unlocked. Here is what I have done so far.

[code]understand “enter code [something]” as entering code.

check entering code:
if the noun is the key pad:
say “You should now type in the code to unlock the garage door”;
otherwise:
say “There is nothing here to enter a code on.”

the key pad is a thing in the laundry room. it is fixed in place. key pad has a number called keycode. the keycode of the key pad is 1234.

understand “keypad” as key pad.

the garagedoor is a door. it is locked.

understand “garage door” as garagedoor.

the garagedoor is north of the laundry room and south of the garage.[/code]

so what i would like is somehow after telling the person to enter a code that the next thing entered would be compared to the number keycode and if it is correct then the door unlocks.

Any help would be greatly appreciated.

I’m not entirely sure what you’re asking (do you just want, basically, a functioning keypad? Or does it have to be the case that the player has to type the code right after reading the sign?) but here’s the [slightly simplified/sanitized to avoid Byzantine Perspective spoilers] code of a keypad I made. It may not be the right way to do it, but it was sufficient for my purposes.

The button panel is [whatever you want it to be; you have "a fixed in place thing in the laundry room"].  "There are square buttons for the digits 0-9 , plus an asterisk and an octothorpe." Understand "panel/buttons/keypad" or "the panel/buttons/keypad" or "button panel" or "the button panel" or "grid" or "the grid" or "the button grid" or "button grid" or "octothorpe" or "asterisk" as the button panel.

Keycode is a number that varies.

Determinately keying in is an action applying to one number and one thing.  

Understand "enter [a number]" or "key in [a number]" or "key [a number] in" or "push [a number]" or "punch in [a number]" as determinately keying in. Understand "enter [a number] into [something]" or "punch in [a number] into [something]" or "key in [a number] into [something]" or "push [a number]" or "push [a number] on [something]" as determinately keying in.  

Rule for supplying a missing second noun while determinately keying in: change the second noun to the button panel.

Check determinately keying in (this is the determinate check rule): 
	if the location does not enclose the button panel:
		say "You can't see anything to enter a number into." instead;
		stop the action;

Instead of determinately keying in keycode:
		[whatever you want to happen; probably "now the garagedoor is unlocked"].

Report determinately keying in: say "You hear the sort of beep that implies that the code you entered has been rejected."
[That is what happens when the player keys in anything that isn't keycode.]


Indeterminately keying in is an action applying to one thing.

Understand "a random number" or "a number" as "[an indeterminate value]".  Understand "key in [an indeterminate value]" or "punch in [an indeterminate value]" or "push [an indeterminate value]" or "enter [an indeterminate value]" as indeterminately keying in.  Understand "enter [an indeterminate value] into [something]" or "punch in [an indeterminate value] into [something]" or "push [an indeterminate value] into/on [something]" as indeterminately keying in.

Instead of pushing the button panel, try indeterminately keying in the button panel.  Instead of attacking the button panel, try indeterminately keying in the button panel.

Rule for supplying a missing noun when indeterminately keying in: change the noun to the button panel.
Does the player mean indeterminately keying in the button panel: it is likely.

Check indeterminately keying in (this is the indeterminate check rule): 
	if the location does not enclose the button panel:
		say "You can't see anything to enter a number into." instead;
		stop the action.

Carry out indeterminately keying in:
	if a random number from 1000 to 9999 is keycode:
		[whatever you want to happen; probably "now the garagedoor is unlocked"];
		stop the action;
	else:
		continue the action.
[Of course, it's not necessary to support the player getting a random chance of entering the right combination, but I did implement it, so here it is.]

Report indeterminately keying in: say "You push a couple of buttons randomly. [/p] (To enter a particular number into the button panel, try [quotation mark]enter <the number>[quotation mark].)"

I hope that helps (or that somebody else posts something closer to what you want).

By the way, if you have any further Inform questions, you should post them to the “Inform 6 and 7 Development” subforum.

Yea i noticed that thread right after I posted the thread. maybe someone can move it.

That idea seems a little to complex. Here is what I would like happen.

understand "enter code [something]" as entering code.

check entering code:
   if in the laundry room:
         say "you walk up to the keypad and start to enter the code.";   
         [right here I need something that waits to see what the player types in  I just dont know how to do that.]
         if what the player typed equals the keycode of the keypad:
             say "the door opens";
         otherwise:
             say "you here a beeping sound signaling the incorrect code has been entered";
    otherwise:
    say "There is nothing here to enter a code on."


the key pad is a thing in the laundry room. it is fixed in place. key pad has a number called keycode. the keycode of the key pad is 1234.

understand "keypad" as key pad.

the garagedoor is a door. it is locked.

understand "garage door" as garagedoor.

the garagedoor is north of the laundry room and south of the garage.

just need to know how to wait on a specific thing to come in from the keyboard. the player needs to enter 1234 after it says you walk up to the key pad and begin entering the code.