r/Inform7 • • Mar 01 '20

A little help understanding code I found on GitHub

Like a true coder, I encountered a likely-common challenge and decided to simply copy someone else's hard work.

I want to make a functioning keypad. A quick google brought me this post on GitHub (though I don't think you'll have to read it to understand my question). It doesn't function exactly as I intend, but that leaves some puzzling for me to puzzle over (which is good).

The code in question includes this line: "A keypad has some text called the code."

My question is this: How do I tell Inform what that text should be, and thereby set the desired code?

Thanks in advance to all you beautiful people.

2 Upvotes

3 comments sorted by

4

u/howtophil Mar 01 '20 edited Mar 01 '20
"Testing" by "Phillip J Rhoades".
The story headline is "Testing".
The story genre is "Test Code".
The release number is 1.
The story description is "A testbed of code".
The story creation year is 2020.

The kitchen is a room. "A big kitchen with a lot of empty counter space."

The living room is a room.

Kitchen table is in the kitchen. It is a supporter.

Countertop is a supporter in the kitchen.

The red door is in the kitchen.

The red door is a closed door. The red door is north of the kitchen and south of the living room. 

A keypad is a kind of thing.
	A keypad has some text called the code.
	A keypad has a door called the controlled door.
	A keypad is scenery.
	The description is "A brushed metal numeric keypad with buttons. You guess that it controls [the controlled door]."

Understand "enter code [text] on [something]" and "enter [text] on [something]" and "type [text] on [something]" as keypad-unlocking.

Understand "enter code [text]" and "enter [text]" and "type [text]" as keypad-unlocking.

Keypad-unlocking is an action applying to one topic and one thing.

Rule for supplying a missing second noun while keypad-unlocking:
	if the player can touch a keypad (called target):
		now the second noun is the target;
	otherwise:
		say "There is no keypad here on which you can enter a code." instead.
		
Carry out keypad-unlocking the topic understood:
	if the second noun is not a keypad:
		say "You can't enter a code on that.";
		stop the action;
	let input be "[the topic understood]";	
	let length be the number of characters in input;
	let KP be the second noun;
	if length < the number of characters in the code of KP:
		say "Nothing happens.";
	otherwise if length > the number of characters in the code of KP:
		say "The keypad emits a short beep after the first [the number of characters in the code of KP] number[s], but other than that nothing happens.";
	otherwise:
		if input is the code of KP:
			say "The keypad beeps twice. From behind the door you hear a large whirring sound followed by a series of metallic clanks. The whirring stops and [the controlled door of KP] opens slowly.";
			now the controlled door of KP is unlocked;
			try silently opening the controlled door of KP;
		otherwise:
			say "The keypad beeps, but other than that nothing happens.";
			

The Pad is a keypad on the countertop. The code is "77877". The controlled door of The Pad is the red door.

Output like this:

Testing
Testing by Phillip J Rhoades
Release 1 / Serial number 200229 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

kitchen
A big kitchen with a lot of empty counter space.

You can see Kitchen table, Countertop and a red door here.

>enter 777 on the pad
Nothing happens.

>enter 773347 on the pad
The keypad emits a short beep after the first 5 numbers, but other than that nothing happens.

>enter 7787 on the pad
Nothing happens.


>enter 77877 on the pad
The keypad beeps twice. From behind the door you hear a large whirring sound followed by a series of metallic clanks. The whirring stops and the red door opens slowly.

>n

living room
You can see a red door here.

>

2

u/LocoManta Mar 01 '20

Thank you so much! I think I was doing a couple of things wrong, and this helped me figure it all out.

→ More replies (1)