Disappearing end story text

Consider the following:

"Disappearing Killer Rabbit" by Philip Riley

Caerbannog is a room. 

The killer rabbit is in Caerbannog.

Every turn:
	if something (called R) that is not the player is in the location:
		say "[The R] advances on you with its nasty, big, pointy teeth! It chops your [']ead clean off! I warned you, but did you listen to me? Oh, no, you knew it all, didn't you? Oh, it's just a harmless little bunny, isn't it? Well, it's always the same. I always tell them--";
		end the story saying "[the R] has killed you.";
		
test me with "z".

This works fine in Inform 10, but in 6M62 the end story text comes out blank: “*** ***”.

For various reasons porting my current game to I10 isn’t feasible. I’m looking for a workaround for this problem – I haven’t been able to figure out why it happens when looking through the old Standard Rules and I6T. Anyone have any ideas?

The problem has to do with trying to use a local variable R outside the rule where it exists. (The death message gets stashed away and printed after the every-turn rule runs.)

You can work around this by defining a global variable:

The cause of death is an object that varies.

Every turn:
	if something (called R) that is not the player is in the location:
		now the cause of death is R;
		say "[The cause of death] advances on you with its nasty, big, pointy teeth! It chops your [']ead clean off! I warned you, but did you listen to me? Oh, no, you knew it all, didn't you? Oh, it's just a harmless little bunny, isn't it? Well, it's always the same. I always tell them--";
		end the story saying "[The cause of death] has killed you.";
1 Like

You can also substitute the text before saying it.

let the final text be the substituted form of "[the R] has killed you";
end the story saying the final text.

Inform should do this automatically (which is why you get the expected behavior in I10), but figuring out when exactly this has to happen is a difficult problem, and it hasn’t always gotten it right.

Thanks, @zarf. I had stared right at the “-by-reference” in Standard Rules.i7x and not considered what it meant. Haven’t programmed C for about 30 years :laughing:

@Draconis – I considered this, but it fails due to the same problem: final text goes out of scope, causing its memory to be deallocated. Inform 10 avoids this by using a reference counter:

To end the story saying (finale - text)
	(documented at ph_endsaying):
	(- deadflag={-by-reference:finale}; BlkValueIncRefCountPrimitive(deadflag); story_complete=false; -).

The next Inform should just implement garbage collection :wink:

1 Like