On a lake with clear water I am able to drink. I cloud not take the water before I found a bottle later. How can I check if the bottle is in my Inventory to fill it. When I write …
if (parent(Bottle) == player)
I got the error:
No such constant as “Bottle”
Compiled with 1 error
Do I have to declare the bottle before checking? In my code the bottle is declared later…
yes, inform has no idea what the bottle is until you declare it. easiest is to do that just above where you need it.
a word of caution, though. your code will work if the player is holding the bottle. but not if the bottle is in a container that is held by the player. that is, if the bottle is in a bag and the player is holding the bag then the parent(bottle) == bag, not player.
if you need to know if it’s anywhere within the player use:
if (IndirectlyContains(player, bottle) ) { do something here... }
this will also work for testing for the presence of objects in anything else and simplifies things when you don’t care about whether an object is in a container or not.
and, by the way. if you’re new to inform/punyinform, or new to IF/coding - i would highly recommend avoiding fillable/pourable liquids if you can. they’re REALLY a pain, even for experienced IF-ers.
if you have to, roger firth has an extensive liquid example in his inform6 FAQs:
EDIT:
oops. just remembered - the firth example relies on dynamic object creation which is a no-go with punyinform (at least not without significant work-arounds). so, never mind. the firth stuff is great stuff otherwise, though.
ah, my bad. i remembered reading somewhere in the punymanual about no dynamic object creation and was conflating the z3 limitations with punyinform itself.
Once you’ve sorted out the order in which things are declared (which is seldom a problem, but it does happen occasionally), there is nothing wrong with what you were doing or what @improvmonster suggested, but there is a slightly easier way to test things.
To test if the bottle is held by the player, use: if (bottle in player) {...}
To test if the bottle is in the current location, but not held by the player, use: if (bottle in location) {...}
To test if the bottle is in a specific container or supporter, use: if (bottle in bag) {...}
To test if the bottle is anywhere in scope, use: if (TestScope(bottle)) {...}
And note what @improvmonster said about liquids. They’re a real pain to do properly and do well. Make sure to account for take, fill, pour, empty, put, drop and all their variations and beware that the clever player can bypass all your hard work, if you’re not careful, using transfer.