Health points

Is there a way to assign a variable akin to health points to the player or characters within the game? Something that could go up or down depending on the actions, of course possibly ending in death?

The example “Lanista 1” shows how to implement hit points, randomized damage, and death: 7.5. Combat and Death

4 Likes

Is ‘attacking’ an action I need to define as a rule or does it exist in Inform already?

It already exists!

1 Like

There is a “block attacking” rule, which I think you’ll need to disable.

find it in the actions index
CM (commands)
attack

delist the block attacking rule
(note that this means you’ll have to account for the player attacking all kinds of things)

2 Likes

You can also do something like “the block attacking rule does nothing when the noun is a combatant” (assuming you have defined “combatants” as a kind of thing that participated in the combat system - could be that you just want “person” if you haven’t done that). This way the default behavior still exists as to anything you haven’t specifically exempted, so less work needed from you versus Drew’s more customized approach.

(To be clear, both should work fine, it’s just a matter of what you prefer and slots more easily into your game!)

3 Likes

Apparently I’ve done something wrong. Any clue?

Instead of attacking Shelly Skinhead: 
    let the damage be a random number between 2 and 10; 
    say "You attack [the noun], causing [damage] points of damage!"; 
    decrease the current hit points of the noun by the damage; 
    if the current hit points of the noun is less than 0: 
        say "[line break][The noun] dies and her soul is sucked into to Valhalla. Her body on 		the other hand is devoured by some charming rats that crawl out of Deep River."; 
        now the noun is nowhere; 
        stop the action; 
    let the enemy damage be a random number between 2 and 10; 
    say "[line break][The noun] attacks you with a combination of swastika decorated brick pieces and brass knuckles, causing [enemy damage] points of damage!"; 
    decrease the current hit points of the player by the enemy damage; 
   	 if the current hit points of the player is less than 0: 
        say "[line break]You had a pretty interesting life but now it's over."; 
        end the story.

Hmm, when I copy and paste the code from your post, it doesn’t throw an error for me.

But having said that, I see two issues here which it can’t hurt to fix anyway:

  1. There’s a superfluous tab in the text here: “Her body on [<TAB>] the other hand [etc.]”.

  2. The last if statement ("if the current hit points of the player is less than 0:") is indented one space extra relative to the preceding line ("decrease ..."), which it shouldn’t be, since it belongs to the same block.

In general, if you get such an error, one way to solve the problem is to re-indent that whole piece of code – manually, but with the help of the IDE.
Start at the topmost statement where the problem occurs (in this case: “Instead of attacking Shelly Skinhead:”), move the cursor to the end of the line, remove any superfluous spaces after the colon, and press Return. The Inform IDE (on Windows, at least) will then automatically start the next line at the proper indentation. Copy-paste just the next line ("let the damage be a random number between 2 and 10;"), move the cursor to the end, press Return, and so on. Do that line by line. The IDE will increase the indentation another level in the lines following a colon (so in this case, after the “if ...:” lines). After an if block is finished, go back one indentation level by pressing Backspace once. If you proceed this way, it’ll be guaranteed that the indentation/formatting is correct. (When the overall definition is very long, it can’t hurt to compile several times while doing this, just to make sure it’s right.)

3 Likes