I hope this is the last time I bother you guys but how do you make a door with a password of a 4 digit number?
Side note: You keep posting these in “General Design Discussions” but you should be posting them in “Inform 6 and 7 Development”
It will also be helpful if you put a summary of the question in the subject line.
[Moved and re-titled]
Check out example #298 - “Safety” in WwI (Writing with Inform). It illustrates a way of implementing a locked safe which could just as easily be used with a locked door.
could you have a link because i cannot seem to know where to find it. Thanks!
You might want to check this post: https://intfiction.org/t/questions-from-a-beginner/13686/7
it doesnt seem to work on playfic as i get the colon indentation error which i have no idea about.
The phrase or rule definition ‘Check pressing it with’ is written using the ‘colon and indentation’ syntax for its 'if’s, 'repeat’s and 'while’s, but that’s only allowed if each phrase in the definition occurs on its own line. So phrases like ‘say " Why are you pressing that? PRESS THE SECURITY GATE. Whoops, spoilers!"’ , which follow directly on from the previous phrase, aren’t allowed.
You’ve probably got your tabs (at the start of lines) mucked up.
As a side note, there are a great many things that doesn’t work on Playfic because it’s running version 6G60 which is from 2010. There have been some major changes in how I7 works since then, so you’re better off downloading it for yourself.
This is very good advice and I second it.
Sorry to leave ya hangin’ there, buddy. I got side-tracked as usual. FYI - Writing with Inform is the name of the documentation that comes with the program itself. Just hit the “Documentation” tab and there’s a numerical index to the examples. I didn’t supply a link on purpose because the tabs tend to get screwed up. When using the examples in the built-in docs, just click on the icon next to the name of the example and the whole thing gets copied over to your source code. (Open up a separate empty project, erasing the name and everything first.)
I looked at “Safety” again and realized that it might not be as helpful as I thought, so I cooked up an example that might be more useful for your particular needs. I kind of forgot that doors and parts of doors can get a little tricky. Anyway, try it out. The code is behind the spoiler tag so it wouldn’t take up so much space. It’s pretty liberally commented so you shouldn’t have any trouble figuring it out, but if you have any questions, don’t hesitate to ask.
[spoiler][code]“Lab” by Michael Tarbert
[create a new action and some ways to understand it:]
Typing it into is an action applying to one number and one thing.
Understand “type [number] in/on/into [something]” or “enter [number] in/on/into [something]” as typing it into.
[catch when readers try typing gibberish:]
Understand “type [text] in/on/into [something]” or “type [text]” as a mistake (“You can only type numbers on something in this game.”).
Understand “enter [text] in/on/into [something]” or “enter [text]” as a mistake (“You can only enter numbers on something in this game.”).
[we add this next to avoid weird guesses from Inform when the player tries “type [a number]” without specifying what to type it into. Comment out this code and see what happens when you try “type 5” while holding the key:]
Does the player mean typing a number into the lab door: it is very likely.
[create the action’s behavior using the standard check/carry out/report rules. Notice we name them all – that helps later with debugging and is considered a best practice for actual works of IF (not neccessary for short code examples, but something to get used to doing IMO):]
Check typing it into (this is the convert typing into the number pad to typing into the lab door rule):
if the second noun is the number pad:
now the second noun is the lab door.
Check typing it into (this is the can only type into the lab door rule):
if the second noun is not the the lab door:
say “[The second noun] does not have a number pad.” instead.
Check typing it into (this is the using wrong combination rule):
if the number understood is not 2018:
say “The number pad readout turns red and reads, ‘ACCESS DENIED’.” instead.
[we only get here if all the checks have passed:]
Carry out typing it into (this is the standard correct combination rule):
if the second noun is locked:
now the second noun is unlocked;
now the second noun is locked.
[any successfully caried out actions should generally be printed out in the “report” phase. Again, this is not a requirement, but a good practice:]
Report typing it into (this is the standard report locking or unlocking lab door rule):
if the second noun is unlocked:
say “The number pad readout turns green and reads, ‘ACCESS GRANTED: UNLOCKING’.”;
say “The number pad readout turns red and reads, ‘ACCESS GRANTED: LOCKING’.”.
[we create a room and connect a special door called “the lab door” in it. We bracket the name in the room description so Inform knows it’s already been mentioned in the description and won’t mention it again in the “You can see… here” part. Also, don’t name the door and the room it connects to with names that could confuse Inform (like “lab door” and “lab”).]
Hallway is a room. “There’s [the lab door] to the north.”
North of the hallway is a door called the lab door.
The Laboratory is a room. “It’s just your standard laboratory.” North of the lab door is the Laboratory.
The description of the lab door is “There’s a number pad on it.”. The lab door is closed and locked.
The number pad is a thing. It is part of the lab door.
The golden key is carried by the player. The description is “The key isn’t special – it’s just a thing that happens to have ‘key’ in the name.”.
[to cover our bases:]
Understand “unlock [something]” as unlocking it with.
Understand “lock [something]” as locking it with.
Rule for supplying a missing second noun while unlocking the lab door with or locking the lab door with: say “There’s no keyhole – just a number pad.” instead.
Instead of unlocking or locking the lab door with: say “There’s no keyhole – just a number pad!”.
[and just to be cool:]
Understand “unlock [something] with [a number]” as typing it into (with nouns reversed).
Understand “lock [something] with [a number]” as typing it into (with nouns reversed).
Test me with “n / open door / i / unlock door / unlock door with key / x key / drop it/ x door / enter code / type xyz / enter 5 / type 5 into pad / enter 2018 into door / open it / n / lock door / close it / lock it with 2018 / s / unlock lab with 2018 / s”.
That’s it. Make sure to select everything in the code box to copy and paste into a fresh project to test it. Hope it helps a little and sorry for the delay.