Is there a way to create a conditional that uses a things examinedness as part of the condition?

I would like to be able to use the fact whether or not an object has been examined in a conditional expression that I am creating. Something like this:

[Code Example 1]
Instead of examining the parchment:
	if the player has the magnifying glass:
		if the diary has been examined:
			say "HAS MAGNIFYING GLASS; HAS EXAMINED DIARY.";
		otherwise:
			say "HAS MAGNIFYING GLASS; HAS NOT EXAMINED DIARY.";
	otherwise:
		if the diary have been examined:
			say "DOES NOT HAVE MAGNIFYING GLASS; HAS EXAMINED DIARY.";
		otherwise:
			say "DOES NOT HAVE MAGNIFYING GLASS; HAS NOT EXAMINED DIARY.".

When I try and compile Code Example 1 I get the following message:

I was trying to match this phrase:

 if (the diary has been examined - a condition): 
But I didn't recognize 'diary has been examined'.

I’ve read through quite a few sections of the documentation (including Writing §9.13. The past and perfect tenses) and did some searches here, but I haven’t been able to figure out how to make the above code compile.

What I did end up doing was creating a truth value that I initially set to false.

examined-diary is a truth state that varies.
examined-diary is false.

And I set this boolean to true when the diary is examined.

now examined-diary is true.

And I modified Code Example 1 to read

[Code Example 2]
Instead of examining the parchment:
	if the player has the magnifying glass:
		if examined-diary is true:
			say "HAS MAGNIFYING GLASS; HAS EXAMINED DIARY.";
		otherwise:
			say "HAS MAGNIFYING GLASS; HAS NOT EXAMINED DIARY.";
	otherwise:
		if examined-diary is true:
			say "DOES NOT HAVE MAGNIFYING GLASS; HAS EXAMINED DIARY.";
		otherwise:
			say "DOES NOT HAVE MAGNIFYING GLASS; HAS NOT EXAMINED DIARY.".

It’s a bit of a kludge so I would still like to know if there is a way to use the examined nature of an object in a conditional expression.

Thanks in advance.

The fancy way to do this is:

if we have examined the diary...

That said, I personally think your solution is better, because Inform 7 isn’t optimized to handle past tense very well, and can run slowly if you add too many past tense checks. A truth state accomplishes the same thing with a minimum of fuss.

(edit: fixed misremembered syntax)

1 Like

See the Example #147: Night Sky.

if we have examined the diary:

works.

Strange… when I test using “if we have examined” within an If block, it only does the otherwise part, no matter how many times you examine it.

Instead of examining the knife:
	if we have examined the knife:
		say "The knife has not changed since you last examined it!";
	otherwise:
		say "Upon closer inspection you confirm it is indeed a knife";

However it works if you put the code in the description of the object like in the night sky example.

The description of knife is "[if we have examined the knife]The knife has not changed since you last examined it![otherwise]Upon closer inspection you confirm it is indeed a knife.[end if]".

If that’s the case, that it only works within the description part of the object definition, then in this case, it might not be the right approach, as the desired scenario is not only checking if this item has been examined but it’s also part of a larger if check comparing other things such as does the player have the magnifying glass.

Personally, as Chin Kee Yong suggests, I would stick with the original ‘kludge’ approach myself.

If you’re checking multiple states (if holding Object2, and if Object1 has been examined, while I examine Object3)
[assuming parchment is not the diary]
then storing the status of these scenarios is vital imo.

You’ll have far more control over how it’s working, when it’s working and why.

The problem lies with your use of “Instead” in this case. Further down, the “Night Sky” example notes:

On the other hand, beware that this would not work as desired:

[example repeated with an Instead rule]

The reason is that our Instead rule has pre-empted normal listening, so Inform considers that we have never successfully heard the message.

If an “Instead” rule intervenes, Inform typically considers the action to have failed. However, we can easily convince it of the opposite by adding rule succeeds to the end of the rule. Then it should work as intended.:

Instead of examining the knife:
	if we have examined the knife:
		say "The knife has not changed since you last examined it!";
	otherwise:
		say "Upon closer inspection you confirm it is indeed a knife";
	rule succeeds.

Alternatively, you can split the definition into two rules:

Instead of examining the knife, say "Upon closer inspection ...".
Instead of examining the knife for more than the first time, say "The knife has not changed ...".
2 Likes

I can confirm that now works.

Good to know! :+1:

Thanks everyone. I now have two approaches that will work.

Approach 1 is setting a truth value, i.e. boolean, when the diary has been examined and using that boolean in my conditional statement.

Instead of examining the diary:
	if the player does not have the glasses:
		say "Can't read.";
	if the player has the glasses:
		say "Very interesting.";
	now examined-diary is true.

...

Instead of examining the parchment:
	if the player has the magnifying glass:
		if examined-diary is true:
			say "HAS MAGNIFYING GLASS; HAS EXAMINED DIARY.";
		otherwise:
			say "HAS MAGNIFYING GLASS; HAS NOT EXAMINED DIARY.";
	otherwise:
		if examined-diary is true:
			say "DOES NOT HAVE MAGNIFYING GLASS; HAS EXAMINED DIARY.";
		otherwise:
			say "DOES NOT HAVE MAGNIFYING GLASS; HAS NOT EXAMINED DIARY.".

Approach 2 is using the actual “examined-ness” state of the diary in the conditional.

Instead of examining the diary:
	if the player does not have the glasses:
		say "Can't read.";
	if the player has the glasses:
		say "Very interesting.";
	rule succeeds.

...

Instead of examining the parchment:
	if the player has the magnifying glass:
		if the diary has been examined:
			say "HAS MAGNIFYING GLASS; HAS EXAMINED DIARY.";
		otherwise:
			say "HAS MAGNIFYING GLASS; HAS NOT EXAMINED DIARY.";
	otherwise:
		if the diary have been examined:
			say "DOES NOT HAVE MAGNIFYING GLASS; HAS EXAMINED DIARY.";
		otherwise:
			say "DOES NOT HAVE MAGNIFYING GLASS; HAS NOT EXAMINED DIARY.".

Both work in isolation.

I’m going to continue using the examined-diary boolean for now but I also added the “rules succeeds” to the end of my diary Instead in case I want to use the diary’s “examined-ness” somewhere else (I had forgotten or didn’t realize that Instead short-circuits the actions it interrupts).

Instead of examining the diary:
	if the player does not have the glasses:
		say "Can't read.";
	if the player has the glasses:
		say "Very interesting.";
	now examined-diary is true;
    rule succeeds.

Thanks again for all your help.

It seems worth pointing out that the light-weight extension called “Epistemology” by Eric Eve (built-in in Inform 6M62) creates a “familiar” property that is set for any object that has been examined by the player. (But note that it won’t work in conjunction with the instead rule approach that you’re using, as things become marked as familiar by a carry out examining rule.) Using it will prevent the need for multiple special-case variables.

Also, note that the “we have examined” syntax does not store information about who the actor was, so if you have NPCs that are executing examine actions, that condition can become true unexpectedly.

2 Likes

This is maybe a nitpicky kind of correction, but the name of the property in Epistemology that tracks whether something is seen is seen; familiar is a different property that’s intended to track whether the PC is aware of something (and is useful for things that the PC hasn’t seen yet, but knows about, or unseeable things, like abstract conversation topics).

I just got bit by that distinction a few days ago and spent a merry half-hour tracking down the bug that arose.

It’s not a nitpick! I was looking quickly at

A thing can be familiar or unfamiliar. A thing is usually unfamiliar.

Carry out examining something visible (this is the mark items as seen on examining rule):
    now the noun is familiar;
    now the noun is seen.

Definition: a thing is known if it is familiar or it is seen.

when I reviewed it, but I had missed that everything visible to the player when looking is marked as familiar, too:

Carry out looking (this is the mark items as seen when looking rule): 
    unless in darkness:
	    now every backdrop in the location is seen;
	    repeat with item running through things that are enclosed by the location:  
		    if the item is not enclosed by an opaque closed container:	
			    now the item is familiar;
			    now the item is seen.

So @billmaya … forget what I said before – it won’t work. You may want to use the extension as a model for something that actually does what you want, however.

For example:

A thing can be inspected.

Carry out examining:
    now the noun is inspected.

if the diary is inspected...

But – again – this approach requires that instead rules not be used to print out the results of examining. (Even if the action is forced to succeed from an instead rule, the carry out rules won’t be processed.)