A few questions about my code

Hi.

I feel like I’m hitting my head against a brick wall. I have what is essentially a working game (use that term loosely). It’s just a small thing I wrote for myself. What is supposed to happen is this. Player wakes up. Player should investigate the room. There should be three things to do: read the book, look through the hole, listen at the door. When all three things have occurred, a man walks in. He asks some questions. Man leaves. Pretty much, the end…

I’ve pasted my whole code for review. Apologies. It’s very messy. Not far from complete though. Thank you very much for any consideration or advice.

Questions.

  1. I’d love to have the banner at the start…then the action. I couldn’t seem to achieve that, so I’ve suppressed the banner altogether. Any ideas on how I can do it (banner then action)?

  2. Really annoying. Reading the book scores 5 points. I cannot get looking through the hole or listening at the door to score 5 points. The actions fail. I cannot work out why. I’m intending to make it so that the man comes in the room when the score is 15.

  3. Better way to script the last part (scene 2 with the questions) without relying on time?

[code]“Patient-42” by Frank Zafka

Include Basic Screen Effects by Emily Short.

The story headline is “A Short Existential Adventure”

The story genre is “existential”

The story description is “You awake in a room, with no memory of who you are, or where you are. Is there a secret for you to discover.”

Use scoring.

Rule for printing the banner text: do nothing.
The describe room stood up into rule is not listed in any rulebook.
The describe room emerged into rule is not listed in any rulebook.
The room description heading rule is not listed in the carry out looking rules.
Rule for printing the name of a room: do nothing.

When play begins:
move player to bed, without printing a room description;
say “[story description]”.

Instead of doing something other than waiting or looking or exiting when the player is in the bed:
say “You cannot do that from the confines of the warm bed.”;
stop the action.

Before exiting when the player is in the bed:
say “You pull back the covers and swing your feet out. Your naked toes curl at the cold of the stone floor. You rise out of the warm bed and look around.”;
continue the action.

The description of the player is “There is no mirror in the room, but looking down at your body, you seem to be a complete human being. You seem to be a paper nightgown, under which you appear to be naked. You rub your head and notice that you have hair. You’re not bald at least.”

The Cell is a room. “The room is small. There is a small single bed. Opposite the bed is a door. There are solid brick walls to the West, East and South.”

A container called the bed is in the cell. The description is “This is the single bed in which you awoke, now unmade. It is has a metal frame (is it brass?) and the mattress is sprung. There is a small duvet. It has no cover, and from the feathers that are protuding in places, we can assume that it is stuffed with bird feathers.” The bed is fixed in place.

The table is in the cell. The description is “Next to your bed is a small table. It has three legs and reaches to your knees. It is made of wood, and appears to be bolted to the floor. Upon the table is a book.” The table is fixed in place.

The chair is in the cell. The description is “There is a small wooden chair. There appears to be nothing special about this chair.” The chair is fixed in place.

A thing has some text called the reading-material. The reading-material of a thing is usually “”.

The book is in the cell. The description is “The book is sitting on the table. Nothing on the cover suggests its contents. It is bound in leather, coloured blue.” The reading-material of the book is “Inside the book are words you understand at least. It appears to be some kind of autobiographical information.: Your name is Louie. You were born 38 years ago. You have a cat called Ziggy. And so on. You turn a page and see the word instruction highlighted with many exclamation marks. Under this heading are these words: Commit as much of this information as possible to memory. You will be interrogated on it, and you will suffer if you answer questions incorrectly.”

After reading the book for the first time:
increase the score by 5;
say “You ask yourself, whether you wrote the book. You don’t remember writing the book, and none of the details seem familiar. You are also curious. What kind of hospital punishes somebody for not being able to remember?”

Waiting more is an action applying to one number.

Understand “wait [a time period]” or “wait for [a time period]” or “wait for a/an [a time period]” or “wait a/an [a time period]” as waiting more.

Carry out waiting more:
let the target time be the time of day plus the time understood;
decrease the target time by one minute;
while the time of day is not the target time:
follow the turn sequence rules.

Report waiting more:
say “It is now [time of day + 1 minute].”

Check waiting more:
if the time understood is greater than one hour, say “You really haven’t got that kind of patience.” instead.

Understand the command “read” as something new.

Reading is an action applying to one thing and requiring light.

Understand “read [something]” as reading.

Check reading:
if the reading-material of the noun is “”:
say "Nothing is printed on [the noun].” instead.

Carry out reading:
say “[reading-material of the noun].”

The West Wall is scenery in the Cell. The description is “Solid cement blocks.”
The South Wall is scenery in the Cell. The description is " Solid cement blooks. You notice that there is a small hole."
The East Wall is scenery in the cell. The description is “Solid cement blocks.”
The North Wall is scenery in the cell. The description is “Solid cement blocks. There is a door in the wall.”
The cell door is north of the cell and south of the hall. The description is “The door is solid. There is no handle upon the door, nor is there any apparent method of opening it. The fit between the door and the wall is perfect. You couldnt fit a single piece of paper between them.” The cell door is a locked closed door.

The Library is a room.

The small hole is a door. The small hole is south of the cell and north of the library. The small hole is a closed unopenable door. It is scenery. Understand “opening” as the hole.

Instead of searching the small hole:
say “Looking through the small hole, you see the room next door is some kind of library. Directly across from the hole is a book shelf, with row upon row of books. Each book appears to be bound in the same kind of leather as the book in your room, but the books have different colour covers (not just blue). You move your eye around the scene, trying to discern anything new. You spend some time looking, but there is nothing more to be learnt from the hole.”

After searching the small hole for the first time:
increase the score by 5;
say “You ask yourself, what are all those books?”

Instead of listening to the cell door:
say “You hear mumbles and other noises coming from behind the door. But you can’t make out anything intelligble.”

After listening to the cell door for the first time:
increase the score by 5;
say “You ask yourself, is this a hospital or a prison?”

To say (relevant time - a time) as 24h time:
let H be the hours part of relevant time;
let M be the minutes part of relevant time;
say “[H]:[if M is less than 10]0[end if][M]”.

Mr X is a man in the hall.

At 8:00 AM:
move Mr X to the cell;
move the player to the bed;
say "Suddenly, the door swings open, and a large man with a clip board walks in. You stumble backwards from the door and sit upon the bed. The man sits down on the chair and gives you a long hard stare. "

At 10:30 AM:
say "Suddenly, the door swings open, and a large man with a clip board walks in. You stumble backwards from the door and sit upon the bed. The man sits down on the chair and gives you a long hard stare. ";
now the command prompt is "What is your name? ".

After reading a command when the command prompt is "What is your name? ":
if the player’s command matches “Louie”:
say “The man seems pleased with the answer.”;
otherwise:
say “'The man frowns. Is that displeasure?”;
now the command prompt is “>”;
reject the player’s command.

At 10:31 AM:
say “The man inhales.”;
now the command prompt is “How old are you?”.

After reading a command when the command prompt is “How old are you?”:
if the player’s command matches “38”:
say “The man seems pleased with the answer.”;
otherwise:
say “'The man frowns. Is that displeasure?”;
now the command prompt is “>”;
reject the player’s command.

At 10:32 AM:
say “The man inhales.”;
now the command prompt is “What is your cat’s name?”.

After reading a command when the command prompt is “What is your cat’s name?”:
if the player’s command matches “Ziggy”:
say “The man seems pleased with the answer.”;
otherwise:
say “'The man frowns. Is that displeasure?”;
now the command prompt is “>”;
reject the player’s command.

At 10:34 AM:
say “The man turns to you and says Tomorrow, you will do better!, and then promptly leaves.”;
Move Mr X to the hall.

At 10:35 AM:
say “You wonder to yourself. What is this all about? What kind of hospital is then? Am I the only patient? You look at the book and you ask yourself, did you write the words inside? Are you Louie?”

At 10:40 AM:
end the story saying “Ha [paragraph break] The End?”;

[/code]

The scores for searching the hole/listening at the door never trigger, because, as far as Inform can tell, the player never actually does either of these things—you have instead rules blocking them. Probably the easiest fix is to change them to report rules.

Report listening to the cell door:
     say "You hear mumbles and other noises coming from behind the door. But you can't make out anything intelligible."

This fix won’t quite work for searching the hole, because Inform will block any attempt to search anything which isn’t a container or a supporter. To get round that, you need to add an extra line.

The can't search unless container or supporter rule does nothing when searching the hole.

I’m not sure what you’re getting at for the banner text—can you describe exactly the effect you want?

Hi. Thanks for that. That’s question 2 resolved. Seems so simple once you know the answer.

As for the banner. I want the game to start > then the banner is presented > then the command line is presented.

This is the with the banner turned on:

[code]You awake in a room, with no memory of who you are, or where you are. Is there a secret for you to discover.
Patient-42
A Short Existential Adventure by Frank Zafka
Release 1 / Serial number 170205 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

The room is small. There is a small single bed. Opposite the bed is a door. There are solid brick walls to the West, East and South.

You can see a cell door, a table, a chair and a book here.

[/code]

This is what I’m looking for, but can’t manage to achieve…

[code]
Patient-42
A Short Existential Adventure by Frank Zafka
Release 1 / Serial number 170205 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

You awake in a room, with no memory of who you are, or where you are. Is there a secret for you to discover.

The room is small. There is a small single bed. Opposite the bed is a door. There are solid brick walls to the West, East and South.

You can see a cell door, a table, a chair and a book here.

[/code]

update
I’ve been working hard, and am pretty happy with the first part. The player scores points for reading the book, looking through the hole and listening to the door. When they’ve done all those actions, the story progresses to the interrogation scene. Here I am really running difficulty. My method of linking together the questions seems very cludgy, and exiting the questions seems near impossible. Would appreciate some further words of wisdom? Obviously I can post my updated code, but didnt want to flood this thread.

If you want to have the story description print after the banner instead of before it, you can use a rule “After printing the banner text for the first time:” instead of “When play begins:”. (You have to say “for the first time” to make sure that the line doesn’t repeat if the player types “version,” which prints the banner text again.)

Also, instead of moving the player to the bed in the rule, you should just be able to declare “The player is in the bed” and the player will start in the bed. Is there a reason you’re doing it differently? (Or, you know, if you didn’t know about that, then that’s a handy thing for you to know!)

I will give those a try. Truthfully, I’m trying things till they work. They call it cargo cult programming. And that’s about as good as I get. I tried lots of permutations. But these were the ones that appeared to work. Thanks for the continued assistance. :slight_smile:

Printing the banner for the first time is initially true. After printing the banner text when printing the banner for the first time is true: say "[story description]"; now printing the banner for the first time is false.

This is what worked for me. Thanks for the suggestion.

So that’s questions 1 + 2 done :slight_smile:

Another way of doing it would be to rearrange the startup sequence.

The display banner rule is listed before the when play begins stage rule in the startup rules.

Simpler than my method. Thanks again. :slight_smile:

Have replaced scoring with truth statements:

[code]hole-looking is a truth state that varies. hole-looking is false.

After searching the small hole for the first time:
now hole-looking is true;

Interrogation is a scene. Interrogation begins when book-reading is true and hole-looking is true and door-listening is true.[/code]

This is working nicely. Still not happy with the chaining together the conversation section…if anyone has any sources I can crib from/suggestions? :slight_smile:

For the sequencing problem, you could do something like this.

Inquisition is a scene. Inquisition begins when we have listened to the cell door and we have searched the hole and we have examined the book.

When Inquisition begins:
	now Mr X is in the Cell;
	ask the first question.

Every turn during Inquisition:
	if the time since Inquisition began is:
		-- 1 minutes: ask the second question; 
		-- 2 minutes: ask the third question;
		-- 4 minutes: remove the inquisitor;
		-- 5 minutes: say "You wonder to yourself. What is this all about? What kind of hospital is then?  Am I the only patient? You look at the book and you ask yourself, did you write the words inside? Are you Louie?";
		-- 10 minutes: end the story saying "Ha [paragraph break] The End?".

To ask the first question:
	say "Suddenly, the door swings open, and a large man with a clip board walks in. You stumble backwards from the door and sit upon the bed. The man sits down on the chair and gives you a long hard stare.";
	now the command prompt is "What is your name? ".

To ask the second question:
	say "The man inhales.";
	now the command prompt is "How old are you? ".

To ask the third question:
	say "The man inhales.";
	now the command prompt is "What is your cat's name? ".

To remove the inquisitor:
	say "The man turns to you and says Tomorrow, you will do better!, and then promptly leaves.";
        remove Mr X from play.

(with your “After reading a command when the command prompt is…” rules unchanged.)

Thanks very much…i will have a look and see what I can do. Ta :slight_smile:

I added this After printing the banner text, say "Written with the assistance of the users of http://www.intfiction.org/."

The story almost works. Not sure I like the end part though. It should really just play out like a cut scene, instead of requiring the player to wait for the appropriate parts.

[code]>listen to door
You hear mumbles and other noises coming from behind the door. But you can’t make out anything intelligble.

Suddenly, the door swings open, and a large man with a clip board walks in. You stumble backwards from the door and sit upon the bed. The man sits down on the chair and gives you a long hard stare.

What is your name?Louie
The man seems pleased with the answer.

w
You can’t go that way.

How old are you?38
The man seems pleased with the answer.

wait
Time passes.

What is your cat called?ziggy
The man seems pleased with the answer.

wait
Time passes.

wait
Time passes.

The man turns to you and says Tomorrow, you will do better!, and then promptly leaves.

wait
Time passes.

You wonder to yourself. What is this all about? What kind of hospital is then? Am I the only patient? You look at the book and you ask yourself, did you write the words inside? Are you Louie?
[/code]

Any other way I can achieve this without requiring the player to wait? Thanks again for the time and effort. :slight_smile:

Does this do something like what you want?

When Inquisition begins:
	now Mr X is in the location;
	say "Suddenly, the door swings open, and a large man with a clip board walks in. You stumble backwards from the door and sit upon the bed. The man sits down on the chair and gives you a long hard stare.";
	now the command prompt is "What is your name? ".

After reading a command when the command prompt is "What is your name? ":
	if the player's command matches "Louie":
		say "The man seems pleased with the answer.";
	otherwise:
		say "'The man frowns. Is that displeasure?";
	now the command prompt is "How old are you? ";
	reject the player's command.

After reading a command when the command prompt is "How old are you? ":
	if the player's command matches "38":
		say "The man seems pleased with the answer.";
	otherwise:
		say "'The man frowns. Is that displeasure?";
	now the command prompt is "What is your cat's name? ";
	reject the player's command.

After reading a command when the command prompt is "What is your cat's name? ":
	if the player's command matches "Ziggy":
		say "The man seems pleased with the answer.";
	otherwise:
		say "'The man frowns. Is that displeasure?";
	now the command prompt is ">";
	reject the player's command;
	say "The man turns to you and says Tomorrow, you will do better!, and then promptly leaves.";
	remove Mr X from play.

Okay. I’ve been working on this hard. This is pretty much the finished version. Couple of questions before I give up.

You should be able to stand on the table and chair. And you should be able to get into the bed, and back out. These are not things I’ve been able to achieve successfully. Any hints/suggestions?

Still not 100% sold on the way the end plays out. Any opinions or alternative methods?

[code]“Patient-42” by Frank Zafka

Include Basic Screen Effects by Emily Short.

The story headline is “A Short Existential Adventure”

The story genre is “existential”

The story description is “[paragraph break]You awake in a room, with no memory of who you are, or where you are. Is there a secret for you to discover?”

use no scoring.

Rule for printing the name of a room: do nothing.
Rule for printing room description details: do nothing.

The display banner rule is listed before the when play begins stage rule in the startup rules.
After printing the banner text, say “Writen with the assistance of the users of http://www.intfiction.org/. Special thanks to jrb and AS.”

The initial room description rule is not listed in the startup rulebook.

Understand “kill [something]” as a mistake (“Violence against yourself or others is not currently warranted.”).
Understand the command “hang” as “kill”.

Understand “yourself” as yourself.

When play begins:
move player to bed, without printing a room description;
say “[story description]”.

Instead of doing something other than waiting or looking or exiting when the player is in the bed:
say “You cannot do that from the confines of the warm bed.”;
stop the action.

Before exiting when the player is in the bed:
say “You pull back the blanket and swing your feet out. Your naked toes curl in response to the cold of the stone floor.”;
continue the action.

The description of the player is “There is no mirror in the room, but looking down at your body, you seem to be a complete human being. You seem to be wearing a paper nightgown, under which you’re naked. You rub your head and notice that you have hair. You’re not bald at least.”

The Cell is a room. “[If the player is in the bed]You cannot see much from the bed [otherwise]The room is small. There are solid brick walls to the West, East and South. The North wall appears to have a door set in it[end if].”

A container called the bed is in the cell. The description is “This is the single bed in which you awoke, now unmade. It is has a metal frame (is it brass?) and the mattress is sprung.” The bed is fixed in place.

Understand “Listen at [something]” as listening to.

Understand “knock on [something]” as knocking on. Knocking on is an action applying to one thing.
Understand “knock at [something]” as knocking on.

After knocking on the door:
say “No matter how hard you bang your fists, nobody comes to see what the commotion is about.”

After entering the bed:
say “You’re not going to discover anything laying down…”

The table is in the cell. The description is “Next to your bed is a small table. It has three legs and reaches to your knees. It is made of wood, and appears to be bolted to the floor.” The table is fixed in place. The table is a supporter.

The chair is in the cell. The description is “There is a small wooden chair. There appears to be nothing special about this chair.” The chair is fixed in place. The chair is a supporter.

The blanket is in the bed. The description is “This is a grey flannel blanket. It has a scratchy texture, but is warm enough.”

A thing has some text called the reading-material. The reading-material of a thing is usually “”.

book-reading is a truth state that varies. book-reading is false.

The book is on the table. The description is “Nothing on the cover suggests its contents. It is bound in leather, coloured blue.” The reading-material of the book is “Inside the book are words you understand at least. It appears to be some kind of autobiographical information: Your name is Louie. You were born 38 years ago. You have a cat called Ziggy. And so on. You turn a page and see the word ‘instruction’ highlighted with many exclamation marks. Under this heading are these words: Commit as much of this information as possible to memory. You will be interrogated on it, and you will suffer if you answer questions incorrectly.”

After reading the book for the first time:
now book-reading is true;
say “You ask yourself, whether you wrote the book. You don’t remember writing it, and none of the details seem familiar. You are also curious. What kind of hospital punishes somebody for not being able to remember?”

Understand the command “read” as something new.

Reading is an action applying to one thing and requiring light.

Understand “read [something]” as reading.

Check reading:
if the reading-material of the noun is “”:
say "Nothing is printed on [the noun].” instead.

Carry out reading:
say “[reading-material of the noun].”

The floor is scenery in the cell. The description is “Cold and seemingly made of stone.”
The ceiling is scenery in the cell. The description is “Too high for you to touch, even if you stood on the chair. Strip lighting provides harsh illumination.”
The West Wall is scenery in the Cell. The description is “Solid cement blocks.”
The South Wall is scenery in the Cell. The description is " Solid cement blocks. You notice a small hole in the wall."
The East Wall is scenery in the cell. The description is “Solid cement blocks.”
The North Wall is scenery in the cell. The description is “Solid cement blocks. There is a door in the wall.”
The cell door is north of the cell and south of the hall. The description is “The door is solid. There is no handle upon the door, nor is there any apparent method of opening it. The fit between the door and the wall is perfect.” The cell door is a locked closed door. The cell door is scenery.

The Library is a room.

The small hole is a door. The small hole is south of the cell and north of the library. The small hole is a closed unopenable door. It is scenery. Understand “opening” as the hole.

The can’t search unless container or supporter rule does nothing when searching the hole.

Report searching the small hole:
say “Looks the same as the last time you peered through it.”

hole-looking is a truth state that varies. hole-looking is false.

After searching the small hole for the first time:
now hole-looking is true;
say “Peering through the small hole, you see the room next door is some kind of library. Directly across from the hole is a book shelf, with row upon row of books. Each book appears to be bound in the same kind of leather as the book in your room, but the books have different coloured covers (not just blue). You move your eye around the scene, trying to discern anything new. You spend some time looking, but there is nothing more to be learnt from the hole.”

Report listening to the cell door:
say “The same sounds you heard last time.”

door-listening is a truth state that varies. door-listening is false.

After listening to the cell door for the first time:
now door-listening is true;
say “You hear mumbles and other noises coming from behind the door. But you can’t make out anything intelligble.”

Inquisition is a scene. Inquisition begins when book-reading is true and hole-looking is true and door-listening is true.

When Inquisition begins:
say “Suddenly, the door swings open, and a large man with a clip board walks in. You stumble backwards from the door and sit upon the bed. The man sits down on the chair and gives you a long hard stare.”;
now the command prompt is "What is your name? ".

After reading a command when the command prompt is "What is your name? ":
if the player’s command matches “Louie”:
say “The man seems pleased with the answer.”;
otherwise:
say “The man frowns. Is that displeasure?”;
now the command prompt is "How old are you? ";
reject the player’s command.

After reading a command when the command prompt is "How old are you? ":
if the player’s command matches “38”:
say “The man seems pleased with the answer.”;
otherwise:
say “The man frowns. Is that displeasure?”;
now the command prompt is "What is your cat’s name? ";
reject the player’s command.

After reading a command when the command prompt is "What is your cat’s name? ":
if the player’s command matches “Ziggy”:
say “The man looks pleased with the answer. [paragraph break]The man stands up and l looks at you. 'Tomorrow you will do better he declares. He promptly exits the room, leaving you alone again.”;
otherwise:
say “The man frowns. Is that displeasure? [paragraph break]The man stands up and l looks at you. 'Tomorrow you will do better he declares. He promptly exits the room, leaving you alone again.”;
now quest-answer is true;
now the command prompt is “>”;
reject the player’s command.

quest-answer is a truth state that varies. quest-answer is false. Finale is a scene. Finale begins when quest-answer is true.

When Finale begins:
	say "You begin to ponder all this strangeness and a thought enters your head. What if the book on the table was from the library next door? What if all those books next door were different biographies? What if another book had been placed upon the bedside table? [paragraph break]How am I to know who I really am? you ask. [paragraph break]";
	end the story saying "Ha".
	[/code]

A few tips:

  • You don’t need the booleans. You can simply go

Inquisition is a scene. Inquisition begins when we have searched the small hole and we have listened to the cell door and we have read the book. .

  • Make the bed enterable.
  • To be able to both stand and sit on a chair, you need to implement a system of postures. Example 396 (“Slouching”) provides a robust one.

Thanks for the suggestions. I have tried all those things previously. But ultimately I couldnt get them to work the way I wanted. Messing with the bed had effects on the start of the story. As for the chair, I think I’ll just leave it the way it is. And I’m sure that I couldnt get it to work without the booleans, the way you suggested.

Anyway, I’m 90% happy. And I’ve learnt that I never want to write any more IF. :slight_smile:

The thing about your Booleans is, they’re duplicating information which Inform tracks anyway. You can always test a condition like “if we have read the book”, it doesn’t need to be specially prepared.

You have an “After entering the bed” rule, but the bed isn’t enterable, so that rule never fires. You probably want to make it an “Instead” rule. (Unless you want the player to be able to return to bed—then you need to make it enterable.)

I do get what you’re saying. It’s just I tried a multitude of things, and this kinda worked. Anyway I’ll check out the bed, but I’m happy with the story as-is. So don’t feel you have to spend any more time on it. Thanks for helping out.

Inform’s state-tracking can be baroque; it relies on assumptions about action success which aren’t true in all games. If it works for you, great. But there’s nothing wrong with building your own booleans. They work too, and can be easier for the author to keep track of. (If the flag is set here and tested there, you know exactly what’s going on with it.)

Zarf— yes, I certainly accept that. I was just responding to Frankzafka’s comment “I’m sure that I couldnt get it to work without the booleans, the way you suggested.”

All I was saying that I tried it without the booleans and couldnt get it working. Remember I’m cargo cult programming here. Putting pieces together without understanding why they work! Anyway…thanks for the help (again) :slight_smile: