Problem with implementation of Roll and Unroll actions

I’m having difficult in implementing a Roll and Unroll command for a piece of paper called a “log”.
Can’t seem to get the log to roll/unroll, but the commands seem to be “firing” as they should.
The state of the log is just not changing.
I know I’ve probably made some obvious error, but can’t see what it is.
Could use a nudge to get me on the right track.

The problem seems to be in section 4 of the following code.
Think it has to do with the resolution of the name of what is being acted upon, but am not sure.
To see what I mean about roll/unroll not working, I’ve included a script called “test unrolling”.

"Mallard v8" by Gary


Section 1 - General

Inclusion relates a thing (called X) to a thing (called Y) when Y is part of X. 
The verb to include (it includes, they include, it included, it is included) implies the inclusion relation.


Section 2 - Decoy

A decoy is a kind of thing.

Room-belonging relates one room (called the home) to one decoy.
Supporter-belonging relates one supporter (called the home) to one decoy.
Container-belonging relates one container (called the home) to one decoy.

The verb to belong to (he belongs to, they belong to, he belonged to) implies the reversed room-belonging relation.
The verb to belong on (he belongs on, they belong on, he belonged on) implies the reversed supporter-belonging relation.
The verb to belong in (he belongs in, they belong in, he belonged in) implies the reversed container-belonging relation.

Definition: A decoy is secured if it is in its home or it is on its home or it is enclosed by the player.
	
Definition: A decoy is unsecured if it is not secured.

To decide which room is the home-room of (item - a decoy):
	let H be the home of item;
	if H is a room, decide on H;
	if H is a thing, decide on the location of H.

Definition: a decoy (called item) is free to go:
	let the best way be the best route from the location of item to the home-room of item, using doors;
	if the best way is a direction, decide yes;
	if the location of item is the home-room of item, decide yes;
	decide no.

Every turn: [You could do this with an every turn rule, or an after rule.]
	repeat with item running through unsecured decoys:
		if the item is free to go:
			say "[The item] spreads its wings and flies back to [the home of item].";
			move the item to the home of item;
		otherwise:
			say "[The item] flaps about uselessly, unable to find its way.".
						
Section 3 - Nano

[Look at modern conveniences for guidance and also Beneath the Surface]
A nano is a kind of container.
A nano is usually openable and closed. It is usually closed.
One nano is part of every decoy.

The description of a nano is usually "It is a small cylinder, somewhat resembling a 45 calibre slug.".
The printed name of a nano is usually "nano".
Understand "[something related by reversed incorporation] nano" as a nano.

Definition: A nano is visible if it is enclosed by the player.
Definition: A nano is invisible if it is not visible.

Instead of doing something to a nano which is invisible:
	say "What nano?".	
	
After examining something which includes a nano:
	say "But; there is a nano epoxied into its underside.".
			
Section 4 - Log

A log is a kind of thing. A log can be rolled or unrolled. A log is usually rolled.
A log has a text called contents.  The contents of a log is usually "Not sure what useful information you expected, but this isn't it!".

One log is inside every nano.

The description of log is usually "[if log is rolled]It is a very narrow roll of paper.[otherwise]It is a narrow strip of paper with, '[contents]', written on it..".

Understand "log/logbook/paper/scroll" as a log.
	
Instead of doing something to a log which is invisible:
	say "What log?".	
	
After examining something which contains a log:
	say "You note that there is a log in it.".

Definition: Something is rollable if it is unrolled and it is carried by player.
Definition: Something is unrollable if it is rolled and it is carried by player.

[Define a new ROLL command]
Understand the command "roll" as something new.
Understand "roll [something]" as rolling.
Rolling is an action applying to one visible thing.
Check Rolling:
	if the noun is not a log or the noun is unrollable, say "The [noun] can't be rolled!" instead;
Carry out rolling:
	Now the noun is rolled.
Report rolling:
	say "As you roll the [noun], the contents are once again hidden from view.";
		
[Define a new UNROLL command]
Understand the command "unroll" as something new.
Understand "unroll [something]" as unrolling.
Unrolling is an action applying to one visible thing.
Check unrolling:
	if the noun is not a log or the noun is rollable, say "[the noun] can't be unrolled!" instead.
Carry out unrolling:
	Now the noun is unrolled.
Report unrolling:
	say "As [the noun] is unrolled, you are able to see the contents of [the noun].";

[Take care of things that can't be rolled or unrolled]
Instead of rolling or unrolling something which is not carried:
	say "You need to be carrying it to do that.";

[Take care of rolling a log before inserting it in a nano]				
Before inserting a log (called the rollable item) into something:
	if the rollable item is unrolled:
		try rolling the rollable item.

[Debugging Code]
Every turn:
	say "DEBUG INFO: [if log is rolled]The log is rolled[otherwise]The log is unrolled[end if].". 

Test unrolling with "take drake / open nano / take log / unroll log / x log"

Section - Main Program Code	

Hallway is a room.
The Hall table is a supporter in the hallway.
A brass key is on the Hall table.
The drake is a decoy on the hall table. The drake belongs on the hall table.

The Passage Door is a an open lockable door. It is west of the hallway and east of the living room.
The brass key unlocks the Passage Door.

The Living room is a room.
The mallard is a decoy in living room. The mallard belongs to the living room.

The Dining room is west of living room.
The box is a container in dining room. The duck is a decoy inside the box. The duck belongs in the box.


Test all with "test drake / test mallard1 / test mallard2 / test duck".

Test drake with "take drake / take brass key / w / close door / lock passage door with brass key/ drop drake / look / unlock passage door with brass key / open door / e"

Test mallard1 with "w / take mallard / drop mallard / take mallard / w / drop mallard / e /e".

Test mallard2 with "w / take mallard / w / take duck / put mallard in box / look / e /e".

Test duck with "w / w / take duck / drop duck / look / e / e".

You don’t need a new “inclusion” relation, the incorporation relation is exactly the same.

The description given to the log type should refer to “the item described”, not “a log”.

Your debugging code looks like it should throw an error, I’m surprised it doesn’t. There’s no object just called “log” in your world model. I imagine Inform must be interpreting it as “if any log is rolled”, which could be the cause of your errors.

I haven’t looked closely at your code, but it seems as though in this:

Check Rolling: if the noun is not a log or the noun is unrollable, say "The [noun] can't be rolled!" instead; Carry out rolling: Now the noun is rolled.

Because the second line ends in a semicolon, the compiler may interpret this as though it’s all one rule. Having two rule definitions one inside the other like this should throw a compiler error, but it doesn’t, and I think the effect is that only one bit of code runs. Maybe try turning that semicolon into a period (or put a line of whitespace after it, which has the same effect).

EDIT: By the way, a good tool here is the “rules” command; type “rules” in the game prompt and then it’ll tell you which rules are firing. That might tell you whether my diagnosis is correct.

Thanks to both of you, it seems to be working.
I feel rather silly missing the “.” at the end of the statements, but it has happened before and will again.
I modified the reference to log in the description.
I also tried the “rules” command. This is a very useful command I even didn’t know existed.
And … I dumped the debugging portion. I understand now why it didn’t work, but not why it compiled and ran at all.

I still think I need to do some tightening of the scoping. I’m a little concerned that the rules and such are a bit “open” and could fire in situations I didn’t intend. I’d appreciate any advice on this topic. I don’t want to wait until I’ve turned the code into an extension or embedded it in a large adventure to be faced with trying to find a scoping problem.

Here is the working code at the moment:

"Mallard v8" by Gary


Section 1 - General

Inclusion relates a thing (called X) to a thing (called Y) when Y is part of X. 
The verb to include (it includes, they include, it included, it is included) implies the inclusion relation.


Section 2 - Decoy

A decoy is a kind of thing.

Room-belonging relates one room (called the home) to one decoy.
Supporter-belonging relates one supporter (called the home) to one decoy.
Container-belonging relates one container (called the home) to one decoy.

The verb to belong to (he belongs to, they belong to, he belonged to) implies the reversed room-belonging relation.
The verb to belong on (he belongs on, they belong on, he belonged on) implies the reversed supporter-belonging relation.
The verb to belong in (he belongs in, they belong in, he belonged in) implies the reversed container-belonging relation.

Definition: A decoy is secured if it is in its home or it is on its home or it is enclosed by the player.
	
Definition: A decoy is unsecured if it is not secured.

To decide which room is the home-room of (item - a decoy):
	let H be the home of item;
	if H is a room, decide on H;
	if H is a thing, decide on the location of H.

Definition: a decoy (called item) is free to go:
	let the best way be the best route from the location of item to the home-room of item, using doors;
	if the best way is a direction, decide yes;
	if the location of item is the home-room of item, decide yes;
	decide no.

Every turn: [You could do this with an every turn rule, or an after rule.]
	repeat with item running through unsecured decoys:
		if the item is free to go:
			say "[The item] spreads its wings and flies back to [the home of item].";
			move the item to the home of item;
		otherwise:
			say "[The item] flaps about uselessly, unable to find its way.".
						
Section 3 - Nano

[Look at modern conveniences for guidance and also Beneath the Surface]
A nano is a kind of container.
A nano is usually openable and closed. It is usually closed.
One nano is part of every decoy.

The description of a nano is usually "It is a small cylinder, somewhat resembling a 45 calibre slug.".
The printed name of a nano is usually "nano".
Understand "[something related by reversed incorporation] nano" as a nano.

Definition: A nano is visible if it is enclosed by the player.
Definition: A nano is invisible if it is not visible.

Instead of doing something to a nano which is invisible:
	say "What nano?".	
	
After examining something which includes a nano:
	say "But; there is a nano epoxied into its underside.".
			
Section 4 - Log

A log is a kind of thing. A log can be rolled or unrolled. A log is usually rolled.
A log has a text called contents.  The contents of a log is usually "Not sure what useful information you expected, but this isn't it!".

One log is inside every nano.

The description of log is usually "[if the item described is rolled]It is a very narrow roll of paper.[otherwise]It is a narrow strip of paper with, '[contents]', written on it.".

Understand "log/logbook/paper/scroll" as a log.
	
Instead of doing something to a log which is invisible:
	say "What log?".	
	
Definition: Something is rollable if it is unrolled and it is carried by player.
Definition: Something is unrollable if it is rolled and it is carried by player.

[Define a new ROLL command]
Understand "roll [something]" as rolling.
Rolling is an action applying to one visible thing.
Check Rolling:
	if the noun is not a log or the noun is unrollable, say "The [noun] can't be rolled!" instead.
Carry out rolling:
	Now the noun is rolled.
Report rolling:
	say "As you roll the [noun], the contents are once again hidden from view.".
		
[Define a new UNROLL command]
Understand "unroll [something]" as unrolling.
Unrolling is an action applying to one visible thing.
Check unrolling:
	if the noun is not a log or the noun is rollable, say "[the noun] can't be unrolled!" instead.
Carry out unrolling:
	Now the noun is unrolled.
Report unrolling:
	say "As [the noun] is unrolled, you are able to see the contents of [the noun].".

[Take care of things that can't be rolled or unrolled]
Instead of rolling or unrolling something which is not carried:
	say "You need to be carrying it to do that.";

[Take care of rolling a log before inserting it in a nano]				
Before inserting a log (called the rollable item) into something:
	if the rollable item is unrolled:
		try rolling the rollable item.

Test unrolling with "take drake / x nano / x log / open nano / x nano / x log / unroll log / x log / take log / x log / unroll log / x log / roll log / unroll log / put log in nano"

Section - Main Program Code	

Hallway is a room.
The Hall table is a supporter in the hallway.
A brass key is on the Hall table.
The drake is a decoy on the hall table. The drake belongs on the hall table.

The Passage Door is a an open lockable door. It is west of the hallway and east of the living room.
The brass key unlocks the Passage Door.

The Living room is a room.
The mallard is a decoy in living room. The mallard belongs to the living room.

The Dining room is west of living room.
The box is a container in dining room. The duck is a decoy inside the box. The duck belongs in the box.


Test all with "test drake / test mallard1 / test mallard2 / test duck".

Test drake with "take drake / take brass key / w / close door / lock passage door with brass key/ drop drake / look / unlock passage door with brass key / open door / e"

Test mallard1 with "w / take mallard / drop mallard / take mallard / w / drop mallard / e /e".

Test mallard2 with "w / take mallard / w / take duck / put mallard in box / look / e /e".

Test duck with "w / w / take duck / drop duck / look / e / e".