How to do:"If location is in same region as X"?

I want to test if the player is currently in the same region as something else.

I tried a plain-English approach:

If location is in the same region as X:

But Inform 7 came back with “I was expecting to read a condition, but instead found some text that I couldn’t understand”

Is there a way to do this test?
If so, Could you control how many levels of nested regions to test for?
Can the test be made generic for different types of X (things, persons, objects, rooms, scenery, backdrops …)?

(Written without having Inform open, so bugs are possible, but the general idea should be correct.) If Y is a room, you can test whether “region of Y is region of X”. If Y is not a room, you can test whether “region of the location of Y is region of X”.

(Maybe that works, but I realised that given that region can be inside each other and are thus somewhat complicated, I shouldn’t be posting this stuff without testing it first.)

Thanks, but I can’t get it to work. I tried different combinations, such as:
if region of location is region of X:
if region of location is region of location of X:
if region of location of location is region of location of X:

but I am still getting the same error message for all of them:
“I was expecting to read a condition, but instead found some text that I couldn’t understand”

In case it matters, X is a backdrop placed “in” a region, and it is not a nested region in this case.

I guess you need to use the relation “is regionally in”. Anyway, it’s possible to write rules like this one (where the grue is an object):

Every turn when the player is regionally in a region (called R):
	if the grue is regionally in R, say "You're about to be eaten by a grue.".
Every turn when the player is regionally in a region (called R):

This doesn’t do what you want if regions are nested. It picks an arbitrary region that the player is in – could be an outer or inner one – and calls it R.

This will work, I believe:

Definition: a region is player-containing if the player is regionally in it.

[...] if X is regionally in a player-containing region: ...

Both of those methods still fail.
(though they did both work when i tried with an X that was a door in a room.)

Here are the relevant parts of code (room definitions and some other irrelevant stuff not included):

Reg1 is a region.
A seagull is a backdrop. It is not scenery. It is in Reg1. The initial appearance of the seagull is "..."

After reading a command when the player's command matches “xyz” and the player is regionally in a region (called R):
	if the seagull is regionally in R: 
		say "You have detected a seagull in [R]";
		rule fails;
	otherwise:
		say "Your attempt fails in [R]. The seagull is in [location of seagull]";
		rule fails.

Definition: a region is player-containing if the player is regionally in it.

After reading a command when the player's command matches “xyy”:
	if seagull is regionally in a player-containing region (called R):
		say "You have detected a seagull in [R].";
		rule fails;
	otherwise:
		say "Your attempt fails in [R]. The seagull is in [location of seagull]";
		rule fails.

Error message after the xyz command (when player is in Reg1):
Your attempt fails in Reg1. The seagull is in nothing.

Error message after the xyy command (player is still in Reg1):
Your attempt fails in nothing. The seagull is in nothing.

How can I detect whether the player is in the same region as the seagull or not?
Having it work through levels of nested regions is not necessary.
Just testing for the innermost region is enough.
(Apparently backdrops can only be moved around to innermost regions.
It threw a runtime error when I tried moving it to an outer one.)

(Note that testing if player is in Reg1 will not work if the seagull moves to a new region)

Backdrops are moved dynamically to put them in the room with the player when appropriate. I must admit I don’t understand the mechanism by which this is done - but I tried a while ago to build a game in which the presence of a backdrop in a room other than the player’s location was tested, and it failed because of this. So I suspect you may need to rethink the seagull, rather than the test.

  • Neutron Decay

If the seagull is a backdrop, and the player is in a region that the seagull is in, won’t the seagull automatically be in the same room as the player? Then “if the seagull is in the location” would work.

Drat! You’re right; I didn’t test my code on a backdrop before I posted it.

It turns out that regional containment doesn’t work on backdrops at all. “If the seagull is regionally in Reg1” returns false, even though you’ve defined the seagull as being in Reg1. I’ve filed a bug on this.

As it turns out, yes. That’s a much simpler solution, isn’t it? :slight_smile: Thanks.

YEAS! Turns out it was that simple.

Big thanks to the lot of you who contributed, especially matt w who came up with the solution and zarf for his show of dedication and persistence in exploring all the wrinkles of the issue.

I don’t have enough knowledge about Inform 7 yet to have a valid opinion, but intuitively I would also consider it a bug if the test "If the is regionally in " does not work.

The rules for placement of backdrops are a bit weird. They can be everywhere, they can be in a region, and they can be in a description of rooms. I think the logic is slightly different for each of those cases. The first two places can be declared as initial conditions, but if you change the placement of the backdrop, you must use the third method. I think.

You can also check whether the player is in a particular region by saying “if the player is in (a region)”, like so.

[code]“Test”

When play begins (this is the set status line rule):
now the left hand status line is " [map region of the location]";
now the right hand status line is “[player’s surroundings]”.

Carry out going (this is the mention seagull rule):
if the player is in the shore begin;
say “You have detected a seagull in [the map region of the location].”;
otherwise if the player is in the city;
say “Your attempt fails in [the map region of the location].”;
otherwise;
say “Nothing here.”;
end if.

Room 00 is A Room. Room 01 is east of Room 00. Room 02 is east of Room 01. Room 03 is east of Room 02. Room 04 is south of Room 00 and southwest of Room 01. Room 05 is south of Room 01, southeast of Room 00, southwest of Room 02 and east of Room 04. Room 06 is south of Room 02, southeast of Room 01, southwest of Room 03 and east of Room 05. Room 07 is south of Room 03, southeast of Room 02 and east of Room 06. Room 08 is south of Room 04 and southwest of Room 05. Room 09 is south of Room 05, southeast of Room 04, southwest of Room 06 and east of Room 08. Room 10 is south of Room 06, southeast of Room 05, southwest of Room 07 and east of Room 09. Room 11 is south of Room 07, southeast of Room 06 and east of Room 10. Room 12 is south of Room 08 and southwest of Room 09. Room 13 is south of Room 09, southeast of Room 08, southwest of Room 10 and east of Room 12. Room 14 is south of Room 10, southeast of Room 09, southwest of Room 11 and east of Room 13. Room 15 is south of Room 11, southeast of Room 10 and east of Room 14.

The City is a region. Room 05, Room 06, Room 09 and Room 10 are in The City.

The Shore is a region. Room 00, Room 01, Room 02, Room 03, Room 04, Room 07, Room 08, Room 11, Room 12, Room 13, Room 14 and Room 15 are in The Shore.

The seagull is in the shore. A seagull is a not scenery backdrop. The initial appearance of the seagull is “A seagull graces the shore.”.

Test me with “se / se / se”.[/code]

You get the same error with “if the seagull is in Reg1”, which should work as well.

Hope this helps.