Action not having expected results; not asking "with what"

I copied and slightly adapted this code from somewhere (…ah, it was here, a discussion from 2014 and suggested code by HanonO). I want the results to be different depending on what item the player uses to attack the cockroach. It’s not prompting me with “what do you want to attack it with” and it’s not giving the results I expect.

So, here’s what I have:

The block attacking rule is not listed in any rulebook.


Attacking it with is an action applying to two things.


Understand "attack [something] with [something preferably held]" as attacking it with.

Instead of attacking something with something:
	try attacking the noun.

Check attacking:
	if the noun is not cockroach:
		say "Why would you want to attack [the noun]?" instead.
		
Check attacking:
	if the noun is dead:
		say "[The noun] is already dead. You hit it again for good measure." instead.
		
Check attacking:
	if the player carries nothing:
		say "You consider attacking the cockroach with your bare hands, but the ick factor is just too much." instead.

Check attacking:
	if the second noun is not the chair leg:
		say "You consider attacking the cockroach with [the second noun], but it doesn't seem like the best tool for the job." instead.

Check attacking:
	if a random chance of 1 in 2 succeeds:
		say "You aim at [the noun] but miss completely as it darts away." instead.

Carry out attacking:
	now the noun is dead.
	
Report attacking:
	say "You vanquish [the noun]. Now you'll be able to sleep tonight...as long as it didn't have any friends."

If I’m carrying nothing, the appropriate response is displayed. If I’m carrying anything else, though, this is what happens (carrying both the letter and the chair leg here):

>attack cockroach
You consider attacking the cockroach with nothing, but it doesn't seem like the best tool for the job.

>attack cockroach with chair leg
You consider attacking the cockroach with nothing, but it doesn't seem like the best tool for the job.

>attack cockroach with letter
You consider attacking the cockroach with nothing, but it doesn't seem like the best tool for the job.

Help please? I look forward to learning where I’ve messed everything up. :wink:

Two different issues here, I think!

The first is that the built-in attacking action is still there, with all its grammar. So “attack cockroach” isn’t going to prompt you with “What do you want to attack it with?”, because it’s simply going to be understood as the attacking action.

You can take care of this by adding:

Understand nothing as attacking.

This eliminates all the commands that can be understood as plain old attacking (rather than attacking it with). Then “attack cockroach” will be picked up as an incomplete form of attacking it with, and you’ll get the question you want.

The second issue is that you redirect all of your attacking it with actions to plain old attacking. But plain old attacking doesn’t have a second noun! So all your second noun checks are going to turn out false, and when you print “[the second noun]” it’s always nothing.

You can solve this by changing your rules to deal directly with attacking it with:

Understand nothing as attacking.

Attacking it with is an action applying to two things.


Understand "attack [something] with [something preferably held]" as attacking it with.

Check attacking something with something when the noun is not the cockroach:
		say "Why would you want to attack [the noun]?" instead.
		
Check attacking a dead thing with something:
	say "[The noun] is already dead. You hit it again for good measure." instead.
		
Check attacking the cockroach with something:
	if the player carries nothing:
		say "You consider attacking the cockroach with your bare hands, but the ick factor is just too much." instead.

Check attacking it with when the second noun is not the chair leg:
	say "You consider attacking the cockroach with [the second noun], but it doesn't seem like the best tool for the job." instead.

Check attacking it with:
	if a random chance of 1 in 2 succeeds:
		say "You aim at [the noun] but miss completely as it darts away." instead.

Carry out attacking it with:
	now the noun is dead.
	
Report attacking it with:
	say "You vanquish [the noun]. Now you'll be able to sleep tonight...as long as it didn't have any friends."

Samsa House is a room.

A person can be dead.

The cockroach is an animal in Samsa House.

Gregor is a man in Samsa House.

The player carries a chair leg.

The player carries a rock.

Also I moved the “if” clauses into rule headers for the most part, just because it looks nicer to me.

There are a couple of things here–one is that the code doesn’t require you to be holding the second noun. Also, if you type “attack gregor” it will ask you what you want to attack him with, before asking why you would want to do it.

Another way to do this would be to keep the attacking action and have some kind of way of telling the attacking action what the weapon is… maybe this would have to be a global variable (it’d be nice to use an action variable, but I can’t think of a quick way to set the second noun of one action to be an action variable of another). That’d let you retain some of your handling of “attack gregor” without a second noun. Or there’s this hack:

Understand nothing as attacking.

Definition: something is nonroachy if it is not the cockroach. 

Understand "attack [something nonroachy]" as attacking.

Instead of attacking something: say "Why would you want to attack [the noun]?"

This allows “attack [something]” to be understood as plain old attacking for anything but the cockroach. Typing “attack cockroach” will be seen as an incomplete form of attacking the cockroach with something.

2 Likes

Thank you @matt_weiner! I made the changes you suggested and it’s mostly working the way I wanted, though if the player is carrying nothing it prompts for a second noun and then says “you can’t see any such thing”. But that’s fine.

For the issue of asking what you want to attack Gregor with first, I just changed the “why attack him” message to something about changing your mind and reining in your violent tendencies. :slight_smile:

I appreciate the help!

1 Like

Glad to help!

I don’t get the behavior you described with the original code, but when I changed the Understand line to this:

Understand "attack [something] with [something carried]" as attacking it with.

I do get some things like this. (If you aren’t carrying anything and you try “attack cockroach,” it goes straight to “You can’t see any such thing.” If you try “attack cockroach with rock” and you aren’t carrying the rock, you also get “You can’t see any such thing.”)

1 Like