Definition: a thing is present if... wait, what?

Hello,

After hours of investigation about why something was not working in my code, I discovered that this bit didn’t work as I expected:

[code]“Absence” by G.

Tony’s Bar is a room. Tony is a man in the bar.

A thing can be present or absent. Definition: a thing is present if it is in the location.[/code]
Now,

shows Tony as absent.

Can you please tell me what exactly the mistake is? Many thanks!

This is a pretty common and very annoying source of bugs.

If you define a property with “A thing can be present or absent,” Inform expects that to be set by hand, using declarations like “Now Tony is present.”

If you define an adjective with “Definition: A thing is present if it is in the location,” Inform will calculate it directly, and you don’t need to add the other line. Also, this won’t show up in the showme because it’s not stored as a property of the thing, since it can be calculated from other stuff.

And if you have both, it leads to bad things–Inform will test the one that’s supposed to be set by hand rather than the one that’s in the Definition.

So you can do this:

[code]
Hello,

After hours of investigation about why something was not working in my code, I discovered that this bit didn’t work as I expected:
Code:

“Absence” by G.

Tony’s Bar is a room. Tony is a man in the bar.

Definition: a thing is present if it is in the location.
Definition: a thing is absent if it is not present.[/code]

Also, “in the location” will only apply if something is directly in the room–if it’s in a container or on a supporter, it won’t count as “in the location.” If you want this to apply to everything in the room, try “…if the location encloses it.”

Thanks Matt,

The problem is that, by running the code I have included above, with “SHOWME TONY” I see “absent” as one of Tony’s properties! So it is not that it doesn’t store it, but it stores “absent”. This is super confusing!

Yes, after doing this mistake earlier on, I’ll never forget about the difference of “in the location” and “enclosed by the location”!!! But in the present case it makes no difference.

I see what you mean. This code below seems to work fine. (I write “regionally…” because this was my original wording.)

[code]“More Absence” by G.

Tony’s Bar is a room. The Restrooms are south of the bar. The Streets are north of the bar.

The Establishment is a region. The Bar and the Restrooms are in the Establishment.

Tony is a man in the bar.

Definition: a thing is present if it is regionally in the map region of the location.

After examining the player:
if tony is present, say “You don’t feel comfortable examining yourself near Tony.”;
else say “You can do this, now that Tony is not here.”[/code]
Damn! This actually means that I have more investigation to do… (Anyway, I’m talking to myself, here…)

Thanks again!

It’s confusing because you’re creating two definitions of the adjective “present”. Then different statements wind up invoking different forms of the word, at random. (Not really at random, but it’s still a bad idea.)

Definition: a thing is present if it is in the location. 
Definition: a thing is absent if it is not present.

A tidier way to write this is

Definition: a thing is present rather than absent if it is in the location. 

Yes, you don’t have to define “absent”. You can always write “not present” anyhow, since it’s a binary property.

Thanks again!

It seems that I have more investigation to do. In my original code I actually only had Definition: a thing is present if it is regionally in the map region of the location. without manually defining the absent, but I still got mysterious issues later on with other things. I’m currently chopping down code to get to the least possible…