Attacking something (Inform 7)

I am very new with Inform 7 and I am trying to make it so you enter a sort of attack sequence with the animal. So far this is what I have but you always win. Do I need the ATTACK extension?

In the basement is a zombie. The zombie is an animal. "It is ugly."
Instead of attacking zombie:
	say "You attacked the zombie.....[line break]";
	say "And won!";
move zombie to Graveyard.

Help please!

What do you want to happen? Purely random combat is possible - take a look at the “Randomness” section (8.18 in my documentation). On the other hand, it can be frustrating to the player. Do you want the zombie to win unless the player has something?

I think the ATTACK extension is definitely worth looking at if you’re writing a combat intensive game and randomness appeals to you, but for most scenarios, it’s probably not worth it. (Also, since you’re quite new to Inform, you may want to wrestle one megabeast at a time. ATTACK is relatively straightforward, but it’s not exactly plug and play, especially if the defaults aren’t quite your thing.)

Here’s a way to introduce a little bit of randomness to the encounter, if that’s what you want.

[code]The Basement is a room. The Graveyard is a room.

In the basement is a zombie. The zombie is an animal. The description of the zombie is “It is ugly.”

Instead of attacking zombie:
if a random chance of 1 in 2 succeeds:
say “You attacked the zombie…[line break]”;
say “And won!”;
move zombie to Graveyard;
otherwise:
say “You attacked the zombie, but lost.”;
move player to Graveyard;[/code]

Thanks for the code but when I paste it I get this:

The phrase or rule definition ‘Instead of attacking zombie’ is written using the ‘colon and indentation’ syntax for its 'if’s, 'repeat’s and 'while’s, where blocks of phrases grouped together are indented one tab step inward from the ‘if …:’ or similar phrase to which they belong. But the tabs here seem to be misaligned, and I can’t determine the structure. The first phrase going awry in the definition seems to be ‘if a random chance of 1 in 2 succeeds’ , in case that helps.

This sometimes happens even when the code looks about right, to the eye, if rows of spaces have been used to indent phrases instead of tabs.

Yeah, copying and pasting to or from the forum breaks the tabs into spaces. It still looks right, but you’ll need to manually tab it. (I think it does that for everyone.)

Oh thank you. Now I am getting this one :blush: Sorry for bothering you.

Problem. You wrote ‘otherwise’ : but the punctuation here ‘:’ makes me think this should be a definition of a phrase and it doesn’t begin as it should, with either ‘To’ (e.g. ‘To flood the riverplain:’), ‘Definition:’, a name for a rule (e.g. ‘This is the devilishly cunning rule:’), ‘At’ plus a time (e.g. ‘At 11:12 PM:’ or ‘At the time when the clock chimes’) or the name of a rulebook, possibly followed by some description of the action or value to apply to (e.g. ‘Instead of taking something:’ or ‘Every turn:’).

Did you insert a line space between “move zombie to Graveyard” and “otherwise:”?
They should be on separate lines, but not with a line between them.

ie.

Line 1;
Line 2;

not

Line 1;

Line 2;

In the second case, Inform will not know where the “otherwise:” lines go.

Ohh ok. What code could I use if I wanted to make the player have a higher chance to kill if they had a certain item. “Gun” for instance?

Well, you’re could just recombine elements you’ve already used before.

There are a lot of different ways to do this. For example, you could have an automatic win.

Instead of attacking the zombie while the player holds the gun: say "BLAM! The zombie's head disappears in a fine mist of blood."; move the zombie to the Graveyard;

More specific instead rules trump less specific rules, so you could have a yet-more-specific rule if the player is holding the gun and has no ammunition.

This works fine - great, even - for fairly small, isolated scenarios. But what if you want a flamethrower and a gun and a poker, and the player might be carrying some or all of them at any given time? Writing out all the permutations gets confusing pretty fast. So let’s introduce a new kind: weapons.

A weapon is a kind of thing. 

Using a new kind allows us to give weapons overall characteristics. For example, all weapons are going to be better at killing something than just punching it. How much more dangerous? Well, there’s a bunch of different ways, again. I’m going to say, though, that the difference is a number out of 100, with 1 being the least lethal (kills 1% of the time) and 100 being the most lethal (kills 100% of the time).

A weapon has a number called lethality.

Okay, so clearly I didn’t tell Inform all that stuff about percentages; that’s for later. Still, though. The other thing I’m going to do is give each weapon its own word. Different weapons attack different ways, and this is a flexible way to personalize messages later on.

 A weapon has some text called action_verb.

Now let’s define some weapons. We could do this in a table - I like tables - but I’ll let you do that later if you want.

The fireplace poker is a weapon carried by the player. The lethality of the poker is usually 10. The action_verb of the poker is "poke". The gun is a weapon in the Basement. The lethality of the gun is usually 50. The action_verb of the gun is "shoot". The flamethrower is a weapon in the Basement. The lethality of the flamethrower is 100. The action_verb of the flamethrower is "toast".

You can always add/take out weapons as you want.

Let’s decide if the player gets to pick which weapon to kill with. I’m going to say no, although the scenario is expandable if you want it to be. The player character will automatically choose the most dangerous thing s/he is carrying or has stashed in a backpack. How does the game know what that is?

Definition: a weapon is lethal if its lethality is 25 or more.

Definitions dealing with numbers allow you to use some new words to describe things. (See 14.7 in my documentation - Making the Verb “to weigh”.) The awesome thing? Now we can talk about the lethalest weapon. My inner grammarian is not pleased, but now the game can choose the most dangerous weapon with no problem. Now we can easily figure out how lethal the player is, based on what’s being carried. But first, one more definition.

Definition: a person is unarmed rather than armed if it does not enclose a weapon.

This just tidies up the code a bit.

To decide what number is the player lethality: if the player is unarmed: decide on 1; otherwise: decide on the lethality of the lethalest weapon enclosed by the player;

This is basically the player’s odds, out of 100, of killing something.

Now we’re going to modify the text I gave you before just a little bit.

Instead of attacking zombie: say "You attack the zombie with [if the player is unarmed]your fists[otherwise][the lethalest weapon enclosed by the player][end if].[paragraph break]"; if a random chance of player lethality in 100 succeeds: say "You [if the player is unarmed]punch out[otherwise][action_verb of the lethalest weapon enclosed by the player][end if] the zombie!"; move zombie to Graveyard; otherwise: say "You miss, and the zombie tears out your throat."; move player to Graveyard;

We start by saying what the player attacks with. (I used this for testing purposes.) Note the use of the “lethalest weapon enclosed by the player”.

Now remember earlier, when we wrote that phrase to figure out how dangerous the player was? That’s what “a random chance of player lethality in 100” is: out of 100, what’s the percent odds that the player will kill? This is just like “a random chance of 1 in 2” except one of the numbers is determined based on the game state.

This is just an initial stab, since I have no idea what you’re looking for, but it introduces some chance of success in any scenario, and complete success with a flamethrower. Just like real life.

This could be way less or way more complicated, depending on what you want done.

A handy trick someone taught me: if you go to the post with the code you want to use and hit the “quote” button, the code will show up with all the tab stops that were originally typed in. Then you can copy-paste it without having to manually replace the spaces with tabs.

This only works if the original poster pasted it in with tabs – if the spaces are in the original post it won’t work. (Basically, this works for stuff people wrote in I7 and then copy-pasted into the comment box, not for stuff they typed into the comment box.) But it’s usually worth trying.

Awesome. That should be a sticky somewhere. (One says, without checking to see if it’s already a sticky.)