Indentation error?

Hello,

I am fairly new here and am struggling my way through Inform 7. I have read up on my problem and just can’t get it to work.

This is my code:

After examining the Book: Unless the player carries the Book: Say "Unfortunately you just don't have the time to read all of it now, but you will take it with for now."; Now the player carries the Book. Say "[line break]You now carrry the Book."; Otherwise if the player carries the Book: [Something else....]

This is the error message:

Problem. The phrase or rule definition ‘After examining the Book’ is written using the ‘colon and indentation’ syntax for its 'if’s, 'repeat’s and 'while’s, where blocks of phrases grouped together are indented one tab step inward from the ‘if …:’ or similar phrase to which they belong. But the tabs here seem to be misaligned, and I can’t determine the structure… and so on.

Where am I making a mistake in the Indentations?

Any help would be greatly appreciated. :wink:

BiB

The mistake is probably the period after “Now the player carries the Book”; you want a semicolon there. You might also want to/need to (I’m not sure) indent everything after “after examining the book” by one tab stop.

–Erik

It looks like the problem is that period, like ektemple said. Otherwise, the indentation looks as though it should work just fine. (You’ve got some code that prevents the player from dropping the book, I assume?)

Ok, obviously I still don’t exactly know the difference between “.” and “;” totally.

Thanks for your input!!! :sunglasses:

Well, I changed my mistake into this:

After examining the Book: Unless the player carries the Book: Say "Unfortunately you just don't have the time to read all of it now, but you will take it with for now."; Now the player carries the Book; Say "[line break]You now carrry the Book."; Otherwise if the player carries the Book: [Something else....]

Guess what: I still get just the same error message. Strange… any other ideas :question:

And “yes”, I want the player to keep the book for now.

BiB

Do you have a tab before the first line, “After examining the book”? There shouldn’t be one there. It’s hard to tell because the forum doesn’t preserve the tabs correctly but the snippet looks like it’s indented one tab too much. The tabs should go like this:

After examining the Book: [NO tab]
[tab]Unless the player carries the Book:
[tab][tab]Say “Unfortunately you just don’t have the time to read all of it now, but you will take it with for now.”;
[tab][tab]Now the player carries the Book;
[tab][tab]Say “[line break]You now carrry the Book.”;
[tab]Otherwise if the player carries the Book:
[tab][tab][Something else…]

Thanks for that Tip. I don’t have a tab after the first lne, but I have one before it. Now, your post just gave me the idea to remove that tab and the code works. Strange. Is there a logical reason for that?

I indented all the text after the room definition (“The Bedroom is a dark room. …”) for better readability and thought it wouldn’t be a problem. Must I remove all the preceding Tabs?

Thanks you guys and gals. :slight_smile: I almost feel embarrassed to ask such newb questions. :slight_smile:

BiB

As far as I know, as long as your code blocks are ‘relatively indented’ you can tab before the first line as much as you want (in other words, you’d need to tab before the following lines as well to keep the relative spacing consistent). Indents before room descriptions are OK too. There probably was a different problem that you corrected.

I made just that experience. That s why I had all these indents before everything but the opening definitions and the room descriptons. I removed them now.[/

Well, maybe. I am just not sure what sinced that’s the only thing I changed before retesting it.

Thank you to all of you for assisting me! :sunglasses: :sunglasses: :nerd:

BiB

I don’t think that’s true: I’ve tried to indent the first line and I can’t get it to work with any combination. As far as I can tell the indented block’s header must start at base level or you get an error. Indentation doesn’t matter if you don’t have any indented blocks inside the main block or if you use the begin…end method.

I keep hoping that Inform will one day handle tabs as elegantly as Python. However, I’m not optimistic since Python is normally edited in fixed-width displays, and actual tab characters are replaced by spaces in most Python-aware editors.

Sure makes it easier to post Python code online…

Juhana, does this compile for you?

"Indentation"

At Night is a room. 
	"The stars are out."

The sky is a backdrop which is everywhere.

	After doing anything:
		say "You bump your head."

It works for me, but I’m still using the old build on Windows.

Yes it does, but so does this:

[code]At Night is a room. “The stars are out.” The sky is a backdrop which is everywhere.

After doing anything:
say "You";        say " see";
        say " stars";

say " everywhere."[/code]
And that’s because the indentation here doesn’t carry any relevant information. If you add another indentation level (i.e. the indentation signifies which block the phrases belong to) it doesn’t compile:

[code]At Night is a room. “The stars are out.” The sky is a backdrop which is everywhere.

After doing anything:
    if the current action is jumping:
        say "You bump your head."[/code]

Wouldn’t it be helpful for the editor to be able to actually visually display the Tabstops? The Windows Explorer shows this nicely in its tree structure (via vertical, dotted lines) or many other coding editors which display various characters like spaces, paragraphs etc.

Just an idea.

BiB

I think that’s a good idea, at least as an option.

Also, one thing that makes good Python editors work is that they force initial space to be just spaces, not a mixture of spaces and tabs. Since after 40 years of computing, there is still no reasonable standard for where tab stops lie, it’s never a good idea to mix them. Since the Inform IDE uses variable-width fonts, it should probably use tabs and not spaces. I would like it very, very much if it automatically converted initial spaces to tabs in a smart way, at least when pasting (and maybe convert them back to spaces when copying - does it already?). It should also complain if it can’t find an unambiguous way to convert spaces to tabs. In my opinon.

I’ve never gotten into the guts of a GUI paste function, so I’m sure there are lots of pesky details, but I would imagine the algorithm to be something like this:

When pasting text or opening up a new document:
    Measure the whitespace at the beginning of every line.
        If there is a mixture of tabs and whitespace, use a preference setting to determine how many spaces equal a tab (probably 8 by default). Convert the tabs to spaces.
        If any line does not have a multiple of four spaces at the beginning, issue a warning, but assume that one tab-stop is the least-common-multiple of all the space counts.
            If you want to be nice, allow a small percentage of lines to have a different multiple, and announce their non-conformance.
            If you want to be extra nice, try to guess what the indentation should be, e.g. a line after a colon should be indented. Of course if it does not conform, don't silently fix it a la Microsoft, just complain!

        Convert the tab stops to actual tabs.
        If the first line of any new block is indented, complain.

Obviously there are a lot of things that can go wrong here. Perhaps they could be announced after the paste, probably as compilation errors… “The line ‘After leaving everything in the dust’ does not appear to be indented correctly because it has spaces instead of tabs/comes at the beginning of a block/etc…”

There could also be an Edit menu option such as “convert initial spaces to tabs with tab stops at [8]”, or “Find suspicious indentation”.

I can see this working well with syntax highlighting…

I don’t have much interest in marking tab stops with symbols or lines, but there are a couple of uservoice suggestions that relate to this issue:

inform7.uservoice.com/forums/573 … es-to-tabs
inform7.uservoice.com/forums/573 … ?ref=title

I could be missing some–the uservoice search function is not the best.

–Erik

Thanks for posting those.

Veering just slightly OT, I’ve found a trick to make cut-n-pasting in this forum a little less painful. This works for me on Vista running IE 8. Take the following code, which compiles fine and has been pasted from the windows IDE:

[code]
Lab is a room.

When play begins:
if the location is Lab:
say “LAB!”;
otherwise:
say “BOO!”.
[/code] If I copy this code from the forum and paste it back into the IDE, it fails to compile because the tab stops have been converted to spaces. Instead, I hit the quote button at the bottom of the message. Then a text box opens for my reply which includes the entire original message, including the code. If I copy and paste the code from the text box editor, the original tab stops are preserved and the code compiles just fine. Of course this only works if the OP copy-n-pasted rather than retyped. Also, you have to remeber to hit cancel or you end up prematurely posting a response consisting of merely a requote. :slight_smile:

Nice! :sunglasses:

Good idea! Works with Opera as well.

BiB