Killing an Animal in Inform 7

I am currently in the beginning stage of creating a game for my Sunday School kids for David and Goliath. I am at a point where David has a staff in his hand at the beginning and I need him to be able to use this staff in order to kill a lion. I don’t need hit points or anything special. These are just kids so keeping it simple is a must. Any help with how to do this would be appreciated. Thanks in advance. I am probably going to need more help as the game progresses to the fight with Goliath and killing him with a stone from a sling shot. :smiley:

This shouldn’t be difficult, but you need to figure out what commands (preferably including all of the things your kids might think to try) you want to implement. ‘hit lion with staff’ ‘hit lion’ (while holding the staff but not mentioning it), ‘swing staff at lion’, and so forth.

Start by implementing these; leave the slingshot and stone for later, as it’s more complicated.

You should be able to find how to implement actions by reading the built-in documentation. You’ll want to use instead rules, I’d guess. And you’ll probably want to get rid of the lion when it’s dead, and drag a new object (a dead lion) into the room. To the player, it will seem that the same object is present, but now it will be a new object (one that’s probably not an animal and will thus react differently to standard library commands).

[code]“Lion” by Hanon Ondricek

Lion’s den is a room. “This is where the lions are kept. Too bad that ladder has been pulled away.”

an animal can be dead or alive. An animal is usually alive.

a lion is a kind of animal.

a feral lion is a lion in lion’s den. “The feral lion [if alive]glowers menacingly at you, blocking your escape to the north[otherwise]lies dead on the rock, leaving the passage to the north clear of enemies[end if].” The description is “[if alive]It is alive and snarling.[otherwise]You’ve defeated it soundly.[end if]”

Check going north from lion’s den:
if feral lion is alive:
say “The lion swipes at you with his claws in a deadly arc. He doesn’t seem to want to let you pass.” instead.

Understand “lion” as a lion. Understand “animal” as an animal.

Escape is north of Lion’s Den.

Every turn when the player is in Escape:
end the story finally saying “One down, nineteen to go…”

The block attacking rule is not listed in any rulebook.

Attacking it with is an action applying to two things.

a weapon is a kind of thing.

a sturdy staff is a weapon in lion’s den. “A sturdy staff leans against one wall.” The description is “[if carried]It’s definitely sturdy[otherwise]It looks pretty sturdy[end if].”

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 feral lion:
say “This creature means you no harm.”

Check attacking:
if the noun is dead:
say “[The noun] has already succumbed to your fury.” instead.

Check attacking:
if the player does not carry a weapon:
say “You don’t think your bare hands will suffice against [the noun].” instead.

Check attacking:
if a random chance of 1 in 2 succeeds:
say “You swing at but miss completely as [the noun] circles, seemingly more eager to attack you.” instead.

Carry out attacking:
now the noun is dead;
increase the score by 1.

Report attacking:
say “You smite [the noun] and leave it broken on the rock.”

test attack with “n/attack lion/take staff/x lion/attack lion with staff/g/g/x lion/n”
[/code]

Hanon’s code is better developed than mine. Here’s what I whipped up. Studying the differences between the two might be helpful to you.

[code]“Lion-Killing” by Author

The Cave is a room. “This low-ceilinged room smells like the lair of a wild beast. A large boulder lies nearby.”

The player carries a staff. The description of the player is “You name is David. You are quite virtuous.” The description of the staff is “It’s long and heavy.”

The lion is an animal in the Cave. The description of the lion is “My, what big teeth it has!”

The boulder is scenery in the Cave. The description of the boulder is “It looks quite heavy.”

The dead lion is a thing. The description is “A mound of fur, around which flies are buzzing.”

Hitting it with is an action applying to two things and requiring light. Understand “hit [something] with [something preferably held]” as hitting it with.

Report hitting it with: say “Your action has no effect.”

Instead of hitting the lion with the staff:
now the lion is nowhere;
now the dead lion is in the Cave;
say “You smite the lion a mighty blow, and it falls dead!”

Instead of attacking the lion:
if the player carries the staff:
try hitting the lion with the staff instead;
otherwise:
say “Attacking a fearsome lion with your bare hands would surely be a mistake!”

Test me with “x lion / hit boulder with staff / drop staff / hit lion / take staff / hit lion / x lion / look”.[/code]

Thank you so much for this code. I was able to alter it a bit and get it to work. This was exactly what I was looking for Jim. Great blessing!

Thank You Hanon for your code as well. It is a bit more advanced for me but I am going to try and power through learning what this and incorporate it into my story as well. I see your name all around the internet with Inform 7 and I know that you are truly do great work with this software. I can only strive to be as good as you.

Gwarsh! thanks!

One more thing on this one. If I wanted to make it so that the player cannot pick up the lion whether it is alive or dead what code would I use? I have tried setting the animal and the lion as being fixed in place but neither of these work.

By default the player can’t take anything inheriting from the “person” type, which includes "animal"s.