Errors with using the 'colon and indentation' syntax

So I’ve been working on some combat in a game I’m making. Here is the source in question:
A person has a number called maximum hit points. A person has a number called current hit points. A person has a number called max damage.
The maximum hit points of the player is 45. The maximum hit points of the Boy is 25.
The current hit points of the player is 35. The current hit points of the Boy is 25.
The max damage of the player is 10. The max damage of the Boy is 8.

Instead of attacking someone: 
	let the damage be a random number between 2 and the max damage of the player; 
	say "You attack [the noun], causing [damage] points of damage!"; 
	decrease the current hit points of the noun by the damage; 
	if the current hit points of the noun is less than 0: 
		say "[line break][The noun] dies, and falls to the ground!"; 
		remove the noun from play; 
		stop the action;

So, for that chunk of code that should be like the new default for attacking someone. If I add a new person, I can choose their max damage, maximum hit points, and current hit points. So If I were to compile this (Of course, with more code) and I were to attack someone they just get attacked and don’t back. And it works, so that’s good. But, there is more. The person “the boy” is a person who fights back. So here’s the code for him:

The Bedroom Two is north of the Upstairs Hallway. "This is a bedroom. The exit is to the south. The room smells terrible, and I would recommend leaving immediately." The Boy is a man in Bedroom Two. "A tall scary looking boy looks down on you."
Every turn:
	if the location of the boy is the location of the player:
		After attacking someone:
			let the enemy damage be a random number between 2 and the max damage of the noun; 
			say "[line break]The boy attacks you, causing [enemy damage] points of damage!"; 
			decrease the current hit points of the player by the enemy damage; 
			if the current hit points of the player is less than 0:  
				say "Their final blow knocks you back and you fall to the ground.";
				end the game in death.

And adding this (Of course, with many other rooms and stuff.) creates this problem:

Problem. The phrase or rule definition ‘Instead of attacking someone’ 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. The first phrase going awry in the definition seems to be ‘let the damage be a random number between 2 and the max damage of the player’ , in case that helps.

This sometimes happens even when the code looks about right, to the eye, if rows of spaces have been used to indent phrases instead of tabs.
Can somebody try to tell me what I’m doing wrong?
I am using inform 7.

Could you perhaps edit your post and re-paste the code, but between code-tags? That way, we will be able to actually see the indentation, and it will make your post much more readable. :slight_smile:

Thanks!

(Somewhat related: if you are doing a lot of combat, take a look at my Inform ATTACK extension. The latest release, complete with manual, can be found here. I would recommend taking a look at the example in Chapter 3 first, so you can see whether it would be useful to you.)

Every turn: if the location of the boy is the location of the player: After attacking someone:
This is what is going wrong. You cannot put rules inside rules. Either something is an “every turn” rule, which happens every turn. Or it is an “After attacking” rule, which happens after attacking. But you cannot have a piece of code that is an “after attacking” rule inside an “every turn” rule – for in which rulebook should it be place?

You probably just want

After attacking the boy:

That’s the problem: You should use tabs to indent when using the ‘colon and indentation’ syntax. Spaces aren’t allowed.

The reason why it looks like it’d work with spaces is that you’re not actually using the colon and indentation syntax if you have only one level of indentation. That is,

Every turn: do something; do something else.
is just a normal code block where whitespace doesn’t matter. Equally legal would be

Every turn: do something; do something else.
As soon as you add a new level (if, repeat, while…) you have to either use tabs to indent or use the begin…end syntax.

Thank you so much for the help! It works great now! :smiley:

There’s a bug that allows nested rules: inform7.com/mantis/view.php?id=417 The compiler parses the syntax but the result is not what the author wants.

I would go with the “every turn” rule over the “after attacking” rule; if the boy is truly aggressive, he ought to attack you whether you just attacked him or not.

Even better, set a flag after the player attacks the boy for the first time so that the boy will subsequently attack every turn, even if the player stops attacking.