Modifying response with current action

I am looking to post a specific bit of text if a player performs a custom action that targets a noun outside of the list. I’ve attempted both an “instead” on the action, and a change at the standard response level.

My attempt at the action. (It compiled, but didn’t behave.)

Instead of calling when the noun is not an AnimalNPC:
     say "explanation text".

This compiles, but does not track the “current action”.

The parser error internal rule response (R) is "[if the player is Kevin and the current action is calling]explanation text[otherwise]That noun did not make sense in this context."

That custom verb if that helps:

Understand "call [any AnimalNPC]" as calling.
Calling is an action applying to one visible thing.

Is there a better/correct way to do this?

The standard way of handling this is by making the action applicable more generally and using check rules to eliminate the non-applicable cases:

Lab is a room. 
An animalNPC is a kind of animal. An animalNPC can be called or uncalled.
The dragon is an animalNPC in the lab.
The dog is an animal in the lab.
The rock is a thing in the lab.

Understand "call [thing]" as calling.
Calling is an action applying to one visible thing.

Check calling (this is the can't call inanimate ojects rule):
	if the noun is not a person:[this includes anything animate like animals]
		say "You can't call something inanimate." instead.

Check calling (this is the can't call nonNPCs rule):
	unless the noun is an animalNPC:
		say "You can only call certain creatures." instead.
		
Carry out calling:
	now the noun is called.
	
Report calling:
	say "You call [the noun].".

Test me with "call rock / call dog / call dragon".

Note that the above check rules will run in source order since they are both equally specific in the rule heading and both named.

ETA: By “standard” I mean that this is the way many of the standard rules work. (For example, “The can’t take other people rule” in the check taking rules.)

1 Like

This is on me for not giving full context (it’s hard to because my game is very big, and I’m being coy about not wanting to talk about my game yet), but what do I do if the noun the player is trying to call is something that doesn’t exist? Say, they’re summoning an animal using a magic spell where “call” is the keyword.

I’ve got a wide set of those keywords using AnimalNPC, and it’s working beautifully using “insteads”, but I’m trying to figure out how to give a custom error message if they try to do something far outside what I’ve accounted for.

The simple way would be to just add:

Understand "call [text]" as a mistake ("You can't call that.").

Although I would probably add a separate action for that to cover different possibilities using topics.

2 Likes

Not sure if I am adding anything helpful here, but ‘current action’ in Inform7, if the action, as defined, must have a direct object (=noun), must include a noun, if you want to refer to it in a rule. For instance, say the player types TAKE THE BOOK. The current action would then be ‘taking the book’ (and not just ‘taking’). To refer to the individual parts of an action, you would use ‘action name part of the current action’(=taking) and ‘noun part of the current action’ (=the book). If the action also takes an indirect object (the second noun), that would be the ‘second noun part of the current action’, etc etc. So in your phrase, ‘if the player is Kevin and the action name part of the current action is calling’, that might work.

For more about ‘current action’, you can check out Section 12.20 of the manual, if only for future reference.

1 Like

That’s all correct, but just to spell things out, the initial problem is that in the code in the OP, the player’s input isn’t even producing the calling action, since the only understand statement uses the AnimalNPC token. So that’s why you’d need to write a new understand statement per @BadParser’s latest post.

2 Likes

One thing to be careful of is that “understand … as a mistake” always overrides other Understand lines. So if you want a mistake to be broader than other grammar lines, you can make a new action (I tend to call it “mistaken calling” or the like).

2 Likes

Yeah, I alluded to this. I tend to use check rules for cases which can fit along similar grammar lines and new actions when the grammar line doesn’t fit. This can be when the player’s input uses a completely different token (like random text or a kind of value instead of an actual object) or the wrong number of tokens.

Here’s a fuller example. It allows “calling” for actual but offstage items, items in the location, random text, and text for which the game author wants special responses:

3 Likes

Thank you for this. It took a while to apply to my code (I should have figured out the whole structure before charging ahead with certain parts of it), but I got it working.

1 Like