Using new adjectives in an if statement--what am I doing wrong?

I have the following (abridged) code:

A person can be holy or unholy. A person is usually holy. 


Understand the command "attack" as something new.
Attacking it with is an action applying to one visible thing and one carried thing.
Understand "attack [someone] with [something preferably held]" as attacking it with.


The maximum attack is a number which varies.
Setting action variables for attacking something with something: 
	if the second noun is a weapon: 
		if the first noun is holy:
			let the maximum attack be the holy damage of the second noun; 
		if the first noun is unholy:
			let the maximum attack be the unholy damage of the second noun; 
		now the damage dealt is a random number between 1 and the maximum attack. 

But Inform 7 throws all kinds of errors, including the following:

In the sentence 'if the first noun is holy', I was expecting to read a condition,
but instead found some text that I couldn't understand - 'first noun is holy'.

I was trying to match this phrase:

 if (first noun is holy - a condition): 

But I didn't recognise 'first noun is holy'.

As well as:

You wrote 'let the maximum attack be the holy damage of the second noun', but when 
a temporary value is created inside an 'if ..., ...' or an 'otherwise ...', it only
lasts until that line is complete - which means it can never be used for anything,
because it goes away as soon as created. To make something more durable, create it
before the 'if' or 'otherwise'.

I was trying to match one of these phrases:

1.  let (maximum attack - a new name) be (holy damage of the second noun - description of relations of values) 
2.  let (maximum attack - a new name) be (holy damage of the second noun - name of kind) 
3.  let (maximum attack - a new name) be (holy damage of the second noun - value) 
4.  let (maximum attack - a temporary named value) be (holy damage of the second noun - value) 

I recognised:

maximum attack = a non-temporary variable, holding a number
holy damage of the second noun = a property whose value is a number, holding a number

What am I doing wrong here? For context, I have defined a kind of thing called weapon with the properties holy damage and unholy damage.

1 Like

There’s a couple of small things in here that the compiler is tripping over. The easiest is that Inform wants you to use just the phrase the noun, not the first noun.

Another is that Inform wants you to pre-declare the action variables that an action has, so, assuming that all you want to associate with the action is the amount of damage that it does (i.e., assuming that the maximum damage number is just an intermediate value to discard after use instead of associating with the action), you could do this:

The attacking it with action has a number called the damage dealt.

The last problem is that inform won’t let you create a temporary variable (with let) on a line inside an if clause because, as it says, the variable will evaporate immediately if it wasn’t already defined. The easy solution here is just to declare the temporary variable before the if clauses:

Setting action variables for attacking something with something: 
	let the maximum attack be zero;
	if the second noun is a weapon: 
		if the noun is holy:
			let the maximum attack be the holy damage of the second noun; 
		else if the noun is unholy:
			let the maximum attack be the unholy damage of the second noun; 
		now the damage dealt is a random number between 1 and the maximum attack.

Notice that initially declaring it to be zero inside the action-setting rule gets it to compile, but trying to make it a global variable by defining it outside the action-setting rule doesn’t. (The let statements inside the rule create a local (“temporary”) variable anyway, so it needs to be defined as a local, not a global, variable in the procedure before it can be set with let inside the if clauses.)

But … I don’t know that you actually need to set action variables here! It seems like all of this could be calculated inside a carry out rule (though you say this is an abridged version of what you’re working on, so maybe not, for reasons I can’t see). But it seems to me that this would work without needing to set action variables, which would get you around the kind-of-fiddly requirements:

A person has a number called hit points. The hit points of a person are usually twelve.
Carry out attacking it with:
	let the maximum attack be zero;
	if the second noun is a weapon:
		if the noun is holy:
			let the maximum attack be the holy damage of the second noun;
		otherwise if the noun is unholy:
			let the maximum attack be the unholy damage of the second noun;
		now the damage dealt is a random number between 1 and the maximum attack;
		decrease the hit points of the noun by the damage dealt;
	else:
		say "You cannot attack [the noun] with [the second noun]. [italic type]Yeesh[roman type].".

Does that help?

2 Likes

Your carry out rule worked, thank you!

For anyone who gets here through Google, here’s the exact code I used:

Carry out attacking it with:
	let the maximum attack be zero;
	if the noun is holy:
		let the maximum attack be the holy damage of the second noun;
	otherwise if the noun is unholy:
		let the maximum attack be the unholy damage of the second noun;
	let the minimum attack be the maximum attack - (0.1 * the maximum attack) to the nearest whole number;
	let the damage dealt be a random number between the minimum attack and the maximum attack;
	decrease the current health of the noun by the damage dealt;
1 Like