"Hitting [something]" with no second verb provided

Hello. In my game, a critical event involves you hitting a table with a gavel to formally start a club meeting. Here’s what my current code looks like. After numerous attempts to get it working on my own, I tried modeling it after the “cutting it with” code in Cragne Manor; source here, by Caleb Wilson.

Right now, the code works so that if the player tries using something else to hit the table, you get a different message. You also can’t hit something else with the gavel; “hit table with gavel” is the only solution that works.

However, I want a shortcut that allows “hit table” to automatically hit the table with the gavel, provided the player has the gavel and the table is in the room. Players will be more inclined to type this, and there’s no need to add an extra step.

Hitting stuff works, but when you just type “hit table”, nothing happens. Additionally, as-is, the text “Hitting the table won’t do any good” gets printed even after you type the correct command. What should I change to fix it?

Understand "hit" or "hitting" as hitting it with.

Hitting it with is an action applying to one touchable thing and one carried thing.

Understand "hit [something] with [something]" as hitting it with.

Check the player hitting something with something:
	if the noun is the table:
		if the second noun is not the gavel:
			say "Traditionally, you hit the table with a gavel, not [the second noun]. And you're a stickler for tradition.";
		else:
			say "You smack the gavel against the table.";
	if the second noun is not the gavel:
		say "That's not something you should be hitting stuff with.";
	else:
		say "Hitting [the noun] won't do any good.";

Instead of trying hitting [this should be "trying hitting the table", but that throws an error]
	if the player carries the gavel:
		try hitting the table with the gavel;
	else:
		say "You're carrying nothing with which to hit it.";

Instead of trying hitting the gavel with the gavel:
	say "Quite impossible.".

Thanks in advance!

I’ve tried to make minimal changes, but what about this?

"Gavel" by Scrooge200 and Jonathan

The Boardroom is a room.
The table is a supporter in the Boardroom.
The gavel is on the table.
The carrot is on the table.

Hitting it with is an action applying to two things.
Understand "hit [something] with [something]" as hitting it with.
Carry out hitting it with:
	if the noun is the table:
		if the second noun is not the gavel:
			say "Traditionally, you hit the table with a gavel, not [a second noun]. And you're a stickler for tradition.";
		else:
			say "You smack the gavel against the table.";
	else if the second noun is not the gavel:
		say "That's not something you should be hitting stuff with.";
	else if the noun is the gavel:
		say "Quite impossible.";
	else:
		say "Hitting [the noun] with the gavel won't do any good.";

Instead of attacking [=hitting] the table:
	if the player carries the gavel:
		try hitting the table with the gavel;
	else:
		say "You're carrying nothing with which to hit it.";	
Testing...
>[1] hit table with carrot
Traditionally, you hit the table with a gavel, not a carrot. And you're a stickler for tradition.

>[2] hit carrot with table
That's not something you should be hitting stuff with.

>[3] hit table with table
Traditionally, you hit the table with a gavel, not a table. And you're a stickler for tradition.

>[4] hit table with gavel
You smack the gavel against the table.

>[5] hit table
You're carrying nothing with which to hit it.

>[6] get gavel
Taken.

>[7] hit table
You smack the gavel against the table.

As an update, it’s maybe less efficient, but I quite like the following way of writing it. It helps me understand what’s what, and would make it easier to add or change something.

Carry out hitting it with:
	if the noun is the table and the second noun is the gavel:
		say "You smack the gavel against the table.";
	else if the noun is the table and the second noun is not the gavel:
		say "Traditionally, you hit the table with a gavel, not [a second noun]. And you're a stickler for tradition.";
	else if the noun is the gavel and the second noun is the gavel:
		say "Quite impossible.";
	else if the noun is not the table and the second noun is the gavel:
		say "Hitting [the noun] with the gavel won't do any good.";
	else if the second noun is not the gavel:
		say "That's not something you should be hitting stuff with.";
Testing...
>[1] hit table with carrot
Traditionally, you hit the table with a gavel, not a carrot. And you're a stickler for tradition.

>[2] hit carrot with table
That's not something you should be hitting stuff with.

>[3] hit table with table
Traditionally, you hit the table with a gavel, not a table. And you're a stickler for tradition.

>[4] hit carrot with gavel
Hitting the carrot with the gavel won't do any good.

>[5] hit table with gavel
You smack the gavel against the table.

>[6] hit table
You're carrying nothing with which to hit it.

>[7] get gavel
Taken.

>[8] hit table
You smack the gavel against the table.

P.S. Apologies in advance if I’m leading you astray. I have a feeling that “applying to two things” and “[something]” could both be improved somehow.

2 Likes

This works great, thank you! I went with your second update to the “carry out hitting it with”, too; makes it easier to read and further checks can be implemented.

1 Like

There is some relevant stuff in Jim Aikin’s book under the heading “Same Action, New Results”.

2 Likes

Oh, I hadn’t heard of that book! I’ll check it out, thank you!

This is making me want to start writing in Inform again, and also learn from criticisms/improvements here. Here’s another means to the same end (without adding to or changing your logic or text). It probably overuses “instead of” but might be even easier to read and modify.

Carry out hitting it with:
	say "That's not something you should be hitting stuff with."
	
Instead of hitting the table with the gavel:
	say "You smack the gavel against the table."
	
Instead of hitting the gavel with the gavel:
	say "Quite impossible."
	
Instead of hitting the table with something:
	say "Traditionally, you hit the table with a gavel, not [a second noun]. And you're a stickler for tradition." 

Instead of hitting something with the gavel:
	say "Hitting [the noun] with the gavel won't do any good."
Testing...

[1] hit carrot with carrot
That’s not something you should be hitting stuff with.

[2] hit table with gavel
You smack the gavel against the table.

[3] hit gavel with gavel
Quite impossible.

[4] hit table with carrot
Traditionally, you hit the table with a gavel, not a carrot. And you’re a stickler for tradition.

[5] hit carrot with gavel
Hitting the carrot with the gavel won’t do any good.

1 Like

I sometimes fall prey to needlessly building more infrastructure than necessary for a specific case, but I don’t think it does any harm here…

Lab is a room.
The table is a supporter.
The table is in the lab.
The player carries the gavel.
The vase is on the table.
The player carries the potato masher.

Hitting it with is an action applying to one touchable thing and one carried thing.

Understand "hit [something] with [something preferably held]" as hitting it with.

A thing can be hittable.
A thing can be a hitting-tool.
The table is hittable.
The gavel is a hitting-tool.

First check hitting it with when the noun is the second noun: instead say "That would be a neat trick."

Check hitting it with when the noun is not hittable: instead say "Hitting [the noun] won't do any good.".

Check hitting it with when the second noun is not a hitting-tool: instead say "That's not something you should be hitting stuff with."

To smack is a verb.
Report hitting it with: say "[We] [smack] [the second noun] against [the noun]."

Test me with "hit vase with masher / hit vase with gavel / hit masher with masher / hit gavel with table / hit table with vase / hit table with gavel"
3 Likes