Rope and Error Messgage

So I took the code for rope direct from the recipe book and put a rope in a cupboard and wanted to tie it to a fixture and make a noose to hang someone on.

Firstly it won’t let me “take rope” and shows this error Glulxe fatal error: Stack overflow in callstub.
Plus it also occurs to me that to make a noose might be harder than I first thought.

Can anyone help?


The Bedroom is a room. The Bedroom contains a cupboard.
The cupboard is an unlocked lockable closed openable container.

A rope is a kind of thing.

Definition: a thing is nonrope if it is not a rope.

Attachment relates things to each other in groups. The verb to be stuck to means the attachment relation.

Definition: a thing is tied if the number of things stuck to it is greater than 1.

Definition: a thing is free if it is not tied.

Definition: a rope is free if the number of nonrope things stuck to it is less than 2.

Definition: a thing is hindering if it is stuck to the noun and it is not within the location.

A thing can be round or unevenly shaped. A thing is usually round.

Definition: something is anchored if it is fixed in place or it is scenery or it is part of an anchored thing.

Definition: something is draggable if it is not had by the player and it is not the player and it is not anchored.

Rule for writing a paragraph about a rope (called the coil):
	if the coil is stuck to something which is in a room (called the next room) which is not the location:
		let the way be the best route from the location to the next room;
		if the way is up or the way is down:
			say "[The coil] runs [way] into [the next room].";
		otherwise:
			say "[The coil] snakes across the floor [way] towards [the next room].";
	otherwise:
		say "There is [a coil] here[if the coil is stuck to a visible nonrope thing], tied to [the list of nonrope visible things which are stuck to the coil][end if]."

To decide what room is the home of (item - a thing):
	if item is a door:
		let front cut be the number of moves from the location to the front side of the item;
		let back cut be the number of moves from the location to the back side of the item;
		if front cut is -1, let front cut be 999;
		if back cut is -1, let back cut be 999;
		if the location encloses the item, decide on the location;
		if front cut is greater than back cut, decide on the back side of the item;
		decide on the front side of the item;
	decide on the location of the item.

Rule for writing a paragraph about a nonrope thing (called the anchor) which is stuck to a rope (called the coil):
	if the coil is in an adjacent room:
		let the next room be the home of the coil;
		let the way be the best route from the location to the next room;
		if the way is up or the way is down:
			say "[The coil] runs [way] from [the anchor] into [the next room].";
		otherwise:
			say "From [the anchor] runs [a coil], heading off toward [the way].";
	otherwise:
		if the coil is stuck to something which is not visible,
			say "[The coil] is tied to [the anchor][if the coil is stuck to something in an adjacent room (called the next room)], and from there runs off towards [the next room][end if]."

After printing the name of a rope (called the tied object) while taking inventory:
	if something nonrope is stuck to the tied object:
		say " (attached to [the list of nonrope things which are stuck to the tied object])";
	otherwise:
		say " (with both ends free)".

Instead of examining a rope (called the cord) when something is stuck to the cord:
	say "[The noun] is tied to [the list of secondary things which are stuck to the noun]."


After examining the player when the player is stuck to something which is not the player:
	say "You're currently lashed to [the list of secondary things stuck to the noun]."

After examining something which is stuck to something secondary:
	say "[The noun] is currently attached to [the list of secondary things stuck to the noun]."


After deciding the scope of the player:
	if something stuck to a rope (called the coil) is in the location, place the coil in scope.

A reaching inside rule:
	if the noun is a rope:
		let the anchor be a random visible thing stuck to the noun;
		if the anchor is touchable, allow access.

Before tying something to a rope:
	if the noun is stuck to the second noun, say "[The noun] and [the second noun] are already tied together." instead;
	if the second noun is not free, say "[The second noun] has no ends free." instead;
	if the noun is round, say "You can't realistically tie anything to [the noun]." instead.

Instead of tying a rope to something:
	try tying the second noun to the noun.

Instead of tying something to a rope:
	now the noun is stuck to the second noun;
	say "You loop [the second noun] around [the noun] and knot firmly."


Instead of tying something to a nonrope tied thing:
	let the coil be a random rope stuck to the second noun;
	try tying the noun to the coil.

Instead of tying a nonrope tied thing to something:
	let the coil be a random rope stuck to the noun;
	try tying the second noun to the coil.

Instead of tying a free nonrope thing to a free nonrope thing:
	if the player carries a free rope (called the coil):
		try tying the noun to the coil;
		if the noun is stuck to the coil and the coil is free:
			try tying the second noun to the coil;
	otherwise:
		say "You lack the requisite spare rope."

Understand "untie [something] from [something]" as untying it from. Understand "untie [something]" as untying  it from.

Rule for supplying a missing second noun while untying something from:
	if the number of secondary things stuck to the noun is 0, say "[The noun] is already entirely free." instead;
	if the noun is a rope:
		if the number of touchable nonrope things which are stuck to the noun > 1:
			say "You'll have to say which thing you want to untie [the noun] from.";
			rule fails;
		otherwise:
			if the number of touchable nonrope things stuck to the noun is 0, say "You can't reach [the random nonrope thing stuck to the noun]." instead;
			let the tied object be a random touchable nonrope thing which is stuck to the noun;
			say "(from [the tied object])[line break]";
			now the second noun is the tied object;
	otherwise:
		if the noun is stuck to a rope (called the tied object):
			say "(from [the tied object])[line break]";
			now the second noun is the tied object.

Untying it from is an action applying to two things.

Before untying a rope from something: try untying the second noun from the noun instead.

Before untying something from a rope:
	if the second noun is not held:
		say "(first picking up [the second noun])[line break]";
		try taking the second noun.

Check untying it from:
	unless the noun is stuck to the second noun or the second noun is stuck to the noun,
		say "[The noun] and [the second noun] are already not tied together." instead.

Carry out untying it from:
	now the noun is not stuck to the second noun.

Report untying it from:
	say "Untied."

After reading a command: now every thing is unmentioned.

Before pulling something anchored: say "[The noun] is firmly anchored." instead.

Instead of pulling something tied:
	if the noun is unmentioned:
		say "The impulse is transmitted to [the list of pullable things stuck to the noun].";
		repeat with item running through pullable things stuck to the noun:
			say "[item]: [run paragraph on]";
			try pulling the item;
		if the noun is a rope and the noun is not within the location:
			if the number of nonrope hindering things is 0, move the noun to the location;
	otherwise:
		continue the action.

Before pulling something which is not visible:
	if the noun is anchored:
		say "[The noun] resists, for whatever reason." instead;
	otherwise:
		let space be the holder of the noun;
		let way be the best route from the space to the location;
		if the way is a direction:
			move the noun to the location;
			say "[The noun] [if the way is up]rises[otherwise]slides[end if] into view." instead;
		otherwise:
			move the noun to the location;
			say "[The noun] slides into view." instead.

Definition: a thing is secondary if it is not the noun.  Definition: a thing is pullable if it is not the noun and it is not the player.


Before going a direction (called the way) when the player has something (called the link) which is stuck to something anchored (called the anchor):
	let the next room be the home of the anchor;
	if the next room is not a room, continue the action;
	if the next room is the location:
		if the link is stuck to at least two anchored things,
			say "You can't go far while you're carrying [the link] tied to [the list of anchored things stuck to the link]." instead;
	otherwise:
		let the safe way be the best route from the location to the next room;
		if the safe way is the way:
			if the player is not stuck to the anchor, say "(coiling up your rope again as you go...)";
		otherwise:
			if the safe way is a direction,
				say "While you have [the link] you can't really head any direction but [best route from the location to the next room]." instead;
			otherwise say "You're tied up here." instead.

Before going a direction (called the way) when the player is stuck to something anchored (called the anchor):
	let the next room be the home of the anchor;
	if the next room is not a room, continue the action;
	if the next room is the location:
		if the player is stuck to at least two anchored things,
			say "You can't go far while you're tied to [the list of anchored things stuck to the player]." instead;
	otherwise:
		if the best route from the location to the next room is the way:
			say "(coiling up your rope again as you go...)";
		otherwise:
			say "Your attachments prevent you going any way but [best route from the location to the next room]." instead.

After going somewhere when the player has something (called the link) which is stuck to something draggable:
	if the player is not stuck to the link:
		say "You drag along behind you [the list of draggable things which are stuck to the link].";
		now every draggable thing which is stuck to the link is in the location;
	continue the action.

Report going somewhere when the player is stuck to something draggable:
	say "You drag along behind you [the list of draggable things which are stuck to the player].";
	now every draggable thing which is stuck to the player is in the location.
	
The cupboard contains a rope.

It looks like the Otranto example code (under §10.6. Ropes in the Inform 7 Recipe Book) assumes that the rope is already tied (stuck) to something. The error seems occur specifically when the rope is inside a container.

Consider if you need to implement the mechanic of tying the rope to any (and every) object? For purposes of simulation that would give you a realistic rope but for the purposes of your story, the rope has a specific purpose - to tie one end to a fixture and to tie itself into a noose. If the player can’t perform any other ropey actions (like tying the rope to random things) that doesn’t detract from the story.

I suggest that this rope simulation is more complicated than you need. The rope can just be a thing. There is a built-in tying action. And you can write special case instead rules for tying the rope to a fixture and tying it to itself (to make a noose). Rough example:

[code]The Bedroom is a room. The Bedroom contains a cupboard.
The cupboard is an unlocked lockable closed openable container. The rope is in the cupboard.

The fixtures are in the bedroom.

Instead of tying the rope to the fixtures:
say “Reaching up, you loop the rope around [the fixtures] securing it with a knot.”

Instead of tying the rope to the rope:
say “You form a loop in the end of the rope and tie it.”[/code]

Ropes are really hard to code. There are all sorts of weird conditions to think about. For instance, in zombie’s suggested code, the first Instead rule will print a message – but it won’t do anything to change the status of the rope. The player will still be carrying the rope, and can walk out of the room with it, even though the game just described it as being tied to something.

It’s a complex, messy business, and requires a lot of careful thought.

[code]The Bedroom is a room. The Bedroom contains a cupboard.
The cupboard is an unlocked lockable closed openable container. The rope is in the cupboard.

The fixtures are in the bedroom.

Instead of tying the rope to the fixtures:
say “Reaching up, you loop the rope around [the fixtures] securing it with a knot.”

Instead of tying the rope to the rope:
say “You form a loop in the end of the rope and tie it.”[/code]

If I type the above code into Inform, something is wrong.
How do I actually hang someone from this rope? Somehow triggering the player to move to another room?

The answer might have something to do with this:

The block tying rule is not listed in the check tying it to rulebook.