I6: Presence of Objects

I used to program in LPC, and to determine if something specific is present in a container it had a present() function, used like


Does something like that exist in Inform?

You can use “Obj1 in Obj2” as a condition which is true if Obj1 is a direct child (directly contained by) Obj2. There are also functions available like “child(Obj)” and “parent(Obj)” (among others). See DM4 Ch I Sec. 3 "The Model World, especially 3.2 “The Object Tree” & 3.4 “Tree Statements” for details.

There is also “IndirectlyContains(obj1,obj2)” which checks for indirect containment and is described in appendix A3 “Library Routines.”

The problem is that I’d need object pointers for that. But what if I don’t have one? I have a class Currency, and on several occasions I generate copies which the player can take. Now he has, say, five credits, and he’s in a shop, and I want to determine IF he has any money on him, and if yes, how much.

The objectloop statement lets you iterate through the contents of the player (or any other object).