Books

Since I’m ridiculously bad at figuring out how to create items, I ended up outright stealing Aaron Reed’s book mechanism to create a book. I added a few basic functions so that the player can turn back pages and consult the book if need be. The problem comes in where there are two books in the same place.

A shoddy example:

[code]
“Waiting Room”

Waiting Room is a room. “A waiting room.”

A thing has some text called printing. The printing of a thing is usually “blank”.

Understand the command “read” as something new. Understand “read [something]” as reading. Reading is an action applying to one thing and requiring light. Carry out reading: say “You read: [paragraph break][printing of the noun][line break]”. Report reading: do nothing.

Check reading:
if the noun is a book, try read-booking the noun instead;
if the printing of the noun is “blank”, say “Nothing is written on [the noun].” instead.

A book is a kind of thing. Understand “book” or “books” or “page” or “pages” as a book. A book has a table name called the contents.

Understand the command “read-book” as something new. Read-booking is an action applying to one visible thing. Understand “read [something]” as read-booking. Check read-booking: if noun is not a book, try examining noun instead.

A book is a kind of thing. Understand “book” or “books” or “page” or “pages” as a book.

A book can be open or closed. A book can be openable. A book is usually closed. A book is always openable. Does the player mean doing something to an open book: it is likely. Check opening a book (called tome): try read-booking tome instead. Check closing a book (called tome): now tome is closed; say “You close [the tome] again.” instead.

A book has a number called current page. The current page of a book is usually 0. To say current page of (tome - a book): let n be the current page of tome; choose row n in the contents of tome; say “[reply entry][paragraph break]”.

A book has a table-name called contents.

Carry out read-booking:
repeat with tome running through books enclosed by location:
now tome is closed;
now noun is open;
if current page of noun is 0, now current page of noun is 1;
say “[if current page of noun is 1]You open [the noun].[paragraph break][end if][current page of noun][if the current page of noun is at most the number of rows in contents of noun - 1]Turn to the next page? Turn back a page?[otherwise][The noun] is turned to the last page.[end if]”.

Check read-booking:
if the player is not holding the book:
say “You can’t read anything from this distance.” instead.

The contents of a book is usually Table of No Contents.

Table of No Contents
topic reply
“BLAH” “BLAH”

Forward-turning is an action applying to one thing.
Back-turning is an action applying to one thing.

Check back-turning book (called tome):
if the book is not open:
try opening the NOUN instead;
if the player is not holding the book:
say “You can’t read anything at this distance.” instead;
otherwise:
decrease the current page of tome by 1;
if current page of tome is less than the number of rows in contents of tome:
now the current page of tome is 0;
say “You close [the tome].” instead;
otherwise:
say “You turn back a page.”;
try read-booking tome instead.

Check forward-turning book (called tome):
if the book is not open:
try opening the NOUN instead;
if the player is not holding the book:
say “You can’t read anything at this distance.” instead;
otherwise:
increase the current page of tome by 1;
if current page of tome is greater than the number of rows in contents of tome:
now the current page of tome is 0;
say “You close [the tome].” instead;
otherwise:
say “You turn to the next page.”;
try read-booking tome instead.

Understand the command “turn” as something new.

Understand “flip to the next [something]” as forward-turning. Understand “flip to next [something]” as forward-turning. Understand “turn [something]” as forward-turning. Understand “turn the [something]” as forward-turning. Understand “turn [something] forward” as forward-turning. Understand “turn to next [something]” as forward-turning. Understand “turn to the next [something]” as forward-turning. Understand “turn next [something]” as forward-turning. Understand “turn the [something] forward” as forward-turning.

Understand “flip to the previous [something]” as back-turning. Understand “flip to previous [something]” as back-turning. Understand “flip back a [something]” as back-turning. Understand “turn back a [something]” as back-turning. Understand “turn back the [something]” as back-turning. Understand “turn [something] back” as back-turning. Understand “turn [something] back one” as back-turning. Understand “turn to [something] previous page” as back-turning. Understand “turn [something] backwards” as back-turning.

The BAD NEWS WEEKLY is a book. BAD NEWS WEEKLY is in the waiting room. The contents of BAD NEWS WEEKLY is the Table of Bad News.

Table of BAD NEWS
topic reply
“Some random pages” “Some ads for life insurance and alarm systems”
“Death” “The headline screams: ‘10 killed in freak balloon accident. Will your child be next?’”

TABLOID NOW is a book. TABLOID NOW is in the waiting room. The contents of TABLOID NOW is the Table of Junk

Instead of consulting a book about a topic listed in the contents of the noun:
say “[reply entry][paragraph break]”.

The current page of TABLOID NOW is 2.

Table of Junk
topic reply
“Babies” “Is that a Baby Bump? YES!”
“Rehab” “Is your favorite star is rehab? YES!”
“Yes” “YES!”[/code]

If you delete one book, the other functions beautifully, but with two, the player can’t turn the page. It simply stays on page 1 forever.

I’m not sure what exactly is causing it, which I suppose is understandable given I didn’t write the base code for the books.

Thanks for any help.

In these lines

[code]Check back-turning book (called tome):
if the book is not open:
try opening the NOUN instead;
if the player is not holding the book:
say “You can’t read anything at this distance.” instead;
otherwise:
decrease the current page of tome by 1;
if current page of tome is less than the number of rows in contents of tome:
now the current page of tome is 0;
say “You close [the tome].” instead;
otherwise:
say “You turn back a page.”;
try read-booking tome instead.

Check forward-turning book (called tome):
if the book is not open:
try opening the NOUN instead;
if the player is not holding the book:
say “You can’t read anything at this distance.” instead;
otherwise:
increase the current page of tome by 1;
if current page of tome is greater than the number of rows in contents of tome:
now the current page of tome is 0;
say “You close [the tome].” instead;
otherwise:
say “You turn to the next page.”;
try read-booking tome instead.[/code]

I think you want to change “the book” to tome: “If tome is not open,” “if player is not holding tome,” etc. Remember, Inform parses “the book” the same as “a book,” so “if the book is not open” will be true if either book is not open, and so on.

[UPDATE: Also, I don’t think you want “if current page of tome is less than the number of rows in contents of tome” in the rule for back-turning, because that’ll always be true after you turn back; maybe “less than 1”?]

Yeah, the book/tome thing is the bug. Inform 7 doesn’t have the greatest debugging tools but one thing you can do is put lines like say “doing this now” in the code blocks of the actions that you’re firing – you would have seen what was happening in this case by doing something like:

Check forward-turning book (called tome):
	if the book is not open:
		say "opening";                      [ <---- debugging say here]
		try opening the NOUN instead;

I think that “the” is actually a blank space and/or “a” thing has tripped me up a million times by now. I’m really thankful to the people here for being so patient and helping me every time I make the exact same mistake. Also thanks for that update. I didn’t notice it until you pointed it out, but yes, with what I had, “turning back a page” just closes the book no matter what.

George, I’m afraid all of that is pretty much lost on me. I don’t think I could make heads or tails of what was happening even if I saw step by step the process since before now I didn’t even know naming the book “tome” made much of a difference…though really I should have realised since “tome” is basically saying “book in question”, I think. Thanks for your time and input though, even if it blew past a giant dummy like me.

The thing is, you can narrow it down to two or three lines of code (whatever’s in the if statement), rather than the whole thing. So if you know this one piece isn’t firing the way you expected, you can deal with that.

I usually start by commenting out bits of extraneous code; where that’s not possible, you can try tracing through the expected reaction.

In a case where the check rule is in question, I might insert a couple debugging say phrases, one right after the check rule starts (to make sure it’s firing as expected), and one after each if statement). That way, you can see that it’s starting, but not carrying through as expected. If it’s not firing at all, that’s some other issue; if it enters the loop but doesn’t perform the way you expect, that’s another thing.

It gets easier, though; there’s a couple things I do with regularity that I’m much better at catching, and certain error messages will appear with such regularity that they’ll cue you to certain mistakes you tend to make.

Ha, no problem, I do this too. It just occurred to me that maybe a way to keep from doing this is to call your local variable the-book instead of tome, as in “Check forward-turning book (called the-book):”, and then you can just say “if the-book is open” etc., which looks like what you want to say. Or maybe that would make it really easy to leave out the hyphen once and completely confuse yourself about where the bug was coming from.