Iterate on found in property members on Inform 6

Greetings:

Is there a way to iterate on the members of the found in property on Inform 6 code?

Or to obtain the first listed location?

Awaiting your kind reply,

found_in can be a single value representing a location, an array of values representing locations, or a routine returning true if the object should be in the current location.

To show the contents of the found_in property, you could do something like this:

[ShowFoundIn obj i address length value;
	if(~~(obj provides found_in))
		print_ret (The) obj, " doesn't provide the found_in property!";
	if(obj.found_in ofclass Routine)
		print_ret (The) obj, ".found_in is a routine!";
	address = obj.&found_in;
	length = obj.#found_in / WORDSIZE;
	for(i = 0 : i < length : i++) {
		value = address-->i;
		if(value == 0)
			print "Found [nowhere].^";
		else
			print "Found in ", (name) value, "^";
	}
];

Call this routine using ShowFoundIn(object);.

This routine will also allow for using the value 0 as a placeholder for a location slot that is sometimes empty.

Here’s a routine to show the first found_in-location for an object:

[ShowFirstFoundIn obj value;
	if(~~(obj provides found_in))
		print_ret (The) obj, " doesn't provide the found_in property!";
	if(obj.found_in ofclass Routine)
		print_ret (The) obj, ".found_in is a routine!";
	value = (obj.&found_in)-->0;
	if(value == 0)
		print "First found [nowhere].^";
	else
		print "First found in ", (name) value, "^";
];
3 Likes

This is precisely what I was looking for.

Much obliged!

1 Like