[I7] Actions changing based on player location.

I really didn’t want to have to post here again so soon, but I’ve run into a problem. I’m finishing up my test project to try to get used to Inform 7 and I ran into a problem. Tonight I decided to test out custom actions. I decided to implement the mostly pointless action Dancing. It looks like this:

[code]Dancing is an action applying to nothing.
Understand “dance” as dancing

Carry out dancing:
say “You start dancing wildly, despite the lack of music. You’re not very good.”[/code]

That works fine, just as intended. Type dance, you dance wildly and not very well. But, I thought, what if a room has music? (Or, in the case of my production game when I start it, what if I want an action to work differently in a specific room?) I decided one of my test rooms would have music, thus dance should work differently there. This is where I have problems. It looks as such:

The Main Bedroom is a room. "You are in your bedroom. It's a rather messy place, really. There's a pile of dirty clothes attempting to gain sentience in the corner. There's also an ancient looking stereo in the corner. West leads to a hall." Instead of dancing if the location is the main bedroom: say "You turn on the stereo and start headbanging to the music. Unfortunately, the stereo somehow got set to the soft rock station. You find yourself headbanging to Phil Collins."

The problem is with the “Instead of Dancing” line. The (relevant) part of the error I get is: " the punctuation here ‘:’ makes me think this should be a definition of a phrase and it doesn’t begin as it should, with either ‘To’ (e.g. ‘To flood the riverplain:’), ‘Definition:’, a name for a rule (e.g. ‘This is the devilishly cunning rule:’), ‘At’ plus a time (e.g. ‘At 11:12 PM:’ or ‘At the time when the clock chimes’) or the name of a rulebook, possibly followed by some description of the action or value to apply to (e.g. ‘Instead of taking something:’ or ‘Every turn:’)."

It works (sort of) if I truncate the first line to “Instead of dancing:” … but then the Dance command doesn’t work at all anywhere else. (Presumably because the player isn’t in the main bedroom there’s nothing to do.) What I have above seems like it should work. I spent a solid hour researching, looking through documentation, etc. This looks like it should work, and it doesn’t. I have a good bit of programming experience and always thought I could program in any language as long as I had a reference. Well, I have a reference and I can’t make something incredibly simple work. It gets annoying.

Anyway, what’s wrong here? Any ideas?

Book of Graham, 7:11. The phrase you want is “Instead of dancing in the main bedroom.”

(The reason why it’s not phrased the other way is because ‘the location’ is the location of the player, and thus would be inappropriate if an NPC was the one dancing.)

Oh really? Hmmm. I actually searched out an “Inform 7 syntax guide” and it seemed to indicate the wrong thing, then, saying I should use “if the location is (room)”

Well, thanks. I’ll get this figured out eventually, I hope.

The syntax guide is not wrong: “if the location is (room)” is a-ok if you’re checking the location of the player, but you can’t tack an if-phrase as is on a rule. You must use “when” or “while” instead. So both of the following are correct:

[code]Instead of dancing when the location is the main bedroom:
say “Dancing!”

Instead of dancing:
if the location is the main bedroom:
say “Dancing!”;
say “Not dancing!”[/code]
What maga was saying is that if you want to be as general as possible and allow dancing as an action even for NPCs you shouldn’t use phrases that restrict the rules only to the player character, but in this case the wording of the message looks like it’d be ok to have the rule apply to the player only.

Yeah, I should know better than to try and explain I7 behaviour last thing before I go to bed. Least of all to myself.

I’d like to point out that a carry out rule should never say anything. A check rule should say something if it’s refusing an action or redirecting it to another action, and a report rule should describe what happens at the carry out stage, but the carry out rulebook itself should be silent. Your refusal would work perfectly well as a check rule:

Check dancing: say "You start dancing wildly, despite the lack of music. You're not very good."; stop the action;

Of course if you want the action to count as a success, you can make it a report rule.

Regarding the “in [room]” syntax - I’ve had problems when combining that with other “when” conditions. For example, this will not compile:

[code]Party is a scene.

Instead of dancing during Party in The Main Bedroom:
say “You really start to get your groove on. You’re not sure why everyone is giving you such funny looks.”[/code]

But if you really need your action to work for NPCs, you can also say “when the location of the actor is [room].”

To be fair, even Standard Rules ignores this for certain actions, like looking and examining. (Anybody know what the reason is for that?)

I think you’ve just switched the order of the clauses; “Instead of singing in Station during Party:” compiles. (I haven’t defined dancing or The Main Bedroom in my dummy project.)

(We talked about this once before; I still can’t figure out where “in Station” is supposed to fit in the Backus-Naur form.)

I don’t know if this is the real reason, but it kinda makes sense that the goal of those actions is seeing the description of a room or an object, so the description is printed in the carry out rules. (c.f. with the taking action the goal is to put something in the player’s inventory, which is done in the carry out rules and report rules confirm that the action has been successful; report rules aren’t needed for looking and examining to confirm that the description was printed.)

That’s always been my impression too. I’m not sure if it really makes sense. A couple of times I’ve written “after looking” rules that print something after the room description, and then got confused when an “after taking” (or whatever) rule suppresses the normal “Taken” message. This can be even more complicated with actions like going, which trigger a look (but in what phase? I can’t remember).

It is part of the nonterminal in the “Backus-Naur form for rules” example of the Recipe Book (Example 383).

I think this illustrates the correct order for adding conditions to an action in a rule preamble:

Instead of exiting from the oven in the Kitchen in the presence of Jamie Oliver while we have not examined the recipe during Lunch Time:

It looks to me that it’s not exactly a looking action; it’s the “describe room gone into rule,” a report an actor going which (for the player) issues the phrase “produce a room description with going spacing conventions,” which in turn invokes the following bit of I6:

(- LookAfterGoing(); -)

I just checked, “actions” does not show a looking action after going, but the relevant rules are firing anyway. I guess it’s an I6 thing. I’m pretty sure the documentation says the Before, Instead, and After rules are not consulted for looking after going.

I would guess that LookAfterGoing() translates roughly as this:

Abide by the check looking rules; Consider the carry out looking rules; Abide by the report looking rules.