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.