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
Is âattackingâ an action I need to define as a rule or does it exist in Inform already?
It already exists!
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)
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!)
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:
-
Thereâs a superfluous tab in the text here: â
Her body on [<TAB>] the other hand [etc.]
â. -
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.)