I7: Rules not firing when I change the player

I have a game where the player’s avatar changes on a regular basis. I have this rule:

Instead of examining the player, say “true”.

The problem is… when I type ‘x me’, it only works for the first avatar (Alice). When I change to the next avatar (Bob), the rule is completely ignored and I just get the Bob’s description. If I change back to Alice, the rule fires.

To me it smells like the compiler has somehow managed to bake a reference to Alice into the rule. Certainly, if I do this:

Instead of examining Alice, say “Alice”.
Instead of examining Bob, say “Bob”.

…everything works as expected.

The big problem is: I cannot reproduce this as a minimal test case. Therefore whatever’s going wrong must be something else in my 12000 word game. And I have no idea where to start debugging. Doing ‘actions on’ doesn’t really help as it doesn’t go into enough detail about what rules are being considered (plus, Inform’s habit of always referring to the player as ‘yourself’ does make distinguishing between players tricky).

I’ve never seen a rule as simple as this completely fail to fire before. Any suggestions?

Have you done a rules trace (by typing “rules all” before examining the player when he is Bob)? One guess I’d make is that maybe you have a more specific “instead of examining…” rule that is firing before your “instead of examining the player” rule.

Ah, I didn’t know such a thing existed. Very useful…

With ‘rules all’, when I’m Bob, I see this:

[Rule “Instead of examining the player” does not apply.]

[Rule “standard examining rule” applies.]

When I’m Alice, of course, the first rule fires as expected.

Is there any way to get it to tell me what it thinks ‘player’ is in that rule?

A change to something like Instead of an actor examining: showme the actor; showme the noun; showme the player; if the actor is the player and the noun is the player: say "true"; otherwise: make no decision. should do the trick. You might have to add rule-ordering lines to get it to fall the same place in the instead rulebook, which is important in case the culprit is a prior rule altering the action.

That’s very interesting.

‘Instead of an actor examining’ always fires, and always says ‘true’. ‘Instead of the player examining’ never fires. According to ‘rules all’ this is the first rule that fires (unless it’s possible for a rule to do something even when ‘rules all’ says ‘does not apply’). The values of ‘actor’, ‘noun’ and ‘player’ are always as expected.

Still can’t reproduce this in a test case, though. Next step is to start bisecting my game, which will be huge amounts of fun.

One thing you could try is changing the actor variable when you change the player variable, like so.

[code]Changing is an action applying to one thing. Understand “Change to [something]” as changing.

Check someone changing (this is the block someone else changing rule):
say “Only you can do that!” instead.

Check changing (this is the standard check changing rule):
if the noun is not a person, say “You can’t do that!” instead.

Carry out changing (this is the standard carry out changing rule):
now the player is the noun;
now the actor is the noun.

Report changing (this is the standard report changing rule):
say “You are now [the printed name of the noun].”.[/code]

Hope this helps.

Oh, for…

Here is a minimal test case.

"Examine thyself" by "David Given"

Place is a room.

Player Alice is a person. She is in Place. The description is "Alice's description."

Bob is a person. He is in Place. The description is "Bob's description."

When play begins:
	now the player is Player Alice;
	remove yourself from play.

Instead of examining the player:
	say "Examining rule fires."
Understand "become [any person]" as shapechanging. 
Shapechanging is an action applying to one thing.

Instead of shapechanging an person:
	if the noun is the player:
		say "You're already [the noun].";
		let old-player be the player;
		now the player is the noun;
		say "You become [the printed name of noun]."

test me with "x me / become bob / x me".

Simply change Alice’s name from ‘Player Alice’ to ‘Alice’ and the problem goes away.

I bet what’s going on is that the ‘player’ in the rule is being treated as shorthand for ‘player alice’ rather than the, you know, actual player.

I think this is a bug — particularly since in the real game I have multiple objects with Player on the front, to distinguish them from the NPC version of the same object…

In general, you don’t need to have a special version of Alice to play and another as NPC: when the player is Alice, you play the person Alice, and Bob is an NPC; when the player becomes Bob, Bob stops being an NPC, and you play him, while Alice becomes just another NPC.
But perhaps you have special reasons for having a player version of some or all persons. If so, just call your player version persons “PlayerAlice” or “Player_Alice” or “Player-Alice” or “PC Alice” etc. rather than “Player Alice” etc.