[i7] Updating a property

Losing my mind with this one. When the player examines the bookshelves it reveals ‘Jamie’ trapped underneath, runs a ‘to say’ which updates a few things, and then subsequent examinations are different. The problem is that it’s pulling the wrong property, ‘JamieRevealed’ before the ‘to say’ has run. I’m sure it’s some silly typo-- what have I done wrong?

Stripped down my code:

Library_Shelving is a supporter in Library. The Library_Shelving is undescribed. The Library_Shelving can be JamieRevealed, JamieNotRevealed, or JamieGone. The Library_Shelving is JamieNotRevealed. The Library_Shelving is not fixed in place. Understand "shelf" and "shelving" and "library shelves" and "shelves" and "bookcases" and "cases" and "book cases" and "book shelves" and "book shelf" as Library_Shelving. The printed name of Library_Shelving is "bookshelf". 

The description of Library_Shelving is "[if the Library_Shelving is JamieNotRevealed]As you might expect, the library is filled with book cases; most are built into the walls and have generally survived the carnage, but all of the free-standing shelving have toppled or been crushed by chunks of broken ceiling.[JamieGroan][otherwise if the Library_Shelving is JamieRevealed]One of the school's students is trapped under the book shelves![otherwise if the Library_Shelving is JamieGone]The bookcases remain crushed and knocked around the room, hopefully without any more students pinned under them."

To say JamieGroan:
	say "[paragraph break]'Unngghnnn...'[paragraph break]";
	say "You hear a muffled groan.[paragraph break][if Alison is in the Library]'What the?' Alison says while turning to look at the broken book shelves.";
	Move Jamie to the Library;
	Now the Library_Shelving is JamieRevealed.`

Thanks for any help!

1 Like

This happens because the engine might evaluate the description before printing it to check what the final contents would be. That means that the “to say JamieGroan” phrase runs “silently” and changes the property’s value.

As a general rule, you shouldn’t use text substitutions that have side effects, i.e. they shouldn’t make any changes to variables, properties or world state. What you’d do is change the state in a separate rule that’s tied to the action and not to the description.

After examining the JamieNotRevealed Library_Shelving:
	move Jamie to the Library;
	now the Library_Shelving is JamieRevealed;
	continue the action.
1 Like

Huh. I’ve used this format throughout my game and this is the first instance where it behaved that way-- which is why I was so confused. Thanks for the advice! I’ll style my code in that way going forward.

You can also put a check in your substitutions, to see whether you’re “expanding text for comparison purposes”; if that evaluates true, it means it’s looking at the description to see if it exists at all (if the description is empty, it’ll say “You see nothing interesting about [the noun]” instead of printing an empty string). If it evaluates false, it’s actually showing it to the player.