Really need help getting hitting to work in Inform 7

Hi,

I’m at a loss here. I’ve consulted the documentation, two interactive fiction authoring chats and tutorials, but I can’t for the life of me understand how to create an item that the player can use to interact with objects and characters in various ways.

Here’s a very basic scenario that I’m trying to get working:

[] There’s a wooden ladle on the floor.
[
] There’s a rat in the room.
[] There’s a door in the room.
[
] If the player hits (or uses ladle on) the rat, it’s replaced with a “dead rat” item.
[] If the player hits (or uses ladle on) the door, a message is printed.
[
] If the player hits (or uses ladle on) themselves, a message is printed.

Can someone please help me figure out how to do this? I’ve been at it for 24 hours, and the Inform 7 documentation, syntax and error messages are too confusing for me to be able to troubleshoot or figure this out. I really need some starter code for item usage.

Thanks in advance!

Have you looked at the Lanista 2 example in the inform 7 recipe book?

inform7.com/learn/man/RB_7_5.html

A trimmed down version of what I linked:

The kitchen is a room. "Kitchen".

A ladle is in the kitchen.

A rat is an animal in the kitchen. "The rat squeals and charges around the room".
dead rat is an animal. the description is "A dead rat. Poor thing."

Understand the commands "attack" and "punch" and "destroy" and "kill" and "murder" and "hit" and "thump" and "break" and "smash" and "torture" and "wreck" as something new. 

Attacking it with is an action applying to one visible thing and one carried thing. Understand "attack [something] with [something preferably held]" as attacking it with.

Understand the commands "punch" and "destroy" and "kill" and "murder" and "hit" and "thump" and "break" and "smash" and "torture" and "wreck" as "attack".

Instead of attacking the rat with the ladle:
	say "You kill the bloody rat!";
	now the rat is nowhere;
	now dead rat is in the kitchen.
	
Instead of attacking yourself with the ladle:
	say "Your head rings like a bell, dummy."

Output example:

Kitchen

The rat squeals and charges around the room

You can also see a ladle here.

>get ladle
Taken.

>hit rat with ladle
You kill the bloody rat!

>look at rat
A dead rat. Poor thing.

>hit self with ladle
Your head rings like a bell, dummy.

Nice code. I think perhaps it would be better to make the dead rat a thing instead of an animal? I expect this to lead to better standard responses.

Agreed. :smiley:

The core idea might not be obvious, so to explain it:

This example defines a new action “attacking it with”, which is separate from the built-in Inform action “attacking”. The new action takes two objects (ATTACK X WITH Y) instead of one (ATTACK X).

It’s not possible to delete a built-in action, but you can rip off all its synonyms (attack, punch, kill, etc) and assign them to a new action.

Another trick is when you make your corpse objects, make them supporters and transfer any lootable possessions there after the NPCs death.

That way you’ll get messages like “On the dead body, you see a rusty dagger and a pouch of gems.” It also should respond to SEARCH BODY correctly in a way that won’t work for an animate object.