[SOLVED] Having 'hit points'.

I can't work out to have a variable which is a number.

I also want to be able to increase or decrease this number, and have it set up so that a message prints and the game ends if it ever gets below 1.

Finally, I want to be able to 'roll against' the attribute: that is, generate a random number, and do one thing if the number if over the attribute and another if it's below.


Are you using the off-line editor?

Off-line:

On the Attributes tab for the player, create a new attribute, "hitpoints", and at the bottom, set it to be an "Integer" (a whole number), and set it to some value.

Then click the "Add change script" button, and a new script attribute will appear, called "changedhitpoints". Click the "Code view" icon (second from right; looks like page of writing), and paste in this code:

if (player.hitpoints <= 0) {
  msg ("You died!")
  finish
}

By the way, you might want to look at this library:
https://github.com/ThePix/quest/wiki/CombatLib

On-line:

If on-line, you will need to do all that in the start script of the game object (top of the Scripts tab of the game object). Click the "Code view" icon (second from right; looks like page of writing), and paste in this code:

player.hitpoints = 12
player.changedhitpoints => {
  if (player.hitpoints <= 0) {
    msg ("You died!")
    finish
  }
}

Either way:

To change the hits, do something like this:

player.hitpoints = player.hitpoints - 10

here's a guide of mine on Attributes and the 'if' Script usage:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk

and there's 4 built-in Randomization Functions:

DiceRoll ( http://docs.textadventures.co.uk/quest/functions/corelibrary/diceroll.html )
GetRandomInt ( http://docs.textadventures.co.uk/quest/functions/getrandomint.html )
GetRandomDouble ( http://docs.textadventures.co.uk/quest/functions/getrandomdouble.html )
RandomChance ( http://docs.textadventures.co.uk/quest/functions/corelibrary/randomchance.html )


here's my old and poor combat code (it was based upon/built from Pertex' combat code structure/design, so all credit goes to Pertex), you can take a look at for ideas on how to do some various combat things:

http://textadventures.co.uk/forum/quest/topic/3348/noobie-hks-help-me-thread#22483
http://textadventures.co.uk/forum/quest/topic/3348/noobie-hks-help-me-thread#22486 (the key/legend for all of my abrevs --- I've learned since to never ever use abrevs ever again, lol)


Hi,

Thanks for the responses. I'm using the off-line version.

However, when I go to the attributes tab for the 'player' object, there's no apparent way to make the attribute an integer. The program asks me to "enter the format string" when I either create the attribute or edit it.


'WHATEVER' Object -> 'Attributes' Tab -> Attributes box (at the bottom I think --- NOT the 'status attributes' box) -> Add -> (see below)

(Object name: WHATEVER)
Attribute Name: whatever
Attribute Type (drop down box, change it from string to...): int // integer
Attribute Value: whatever // usually '0' for its initial/starting Value


the 'status attributes' box (which is just a built-in special String Dictionary Attribute) is for the DISPLAYMENT of Attributes during the game on the right hand side. If you do want to display your Attributes, you need to create/add them first, as you can't display what doesn't exist, lol.


here's a demo game step by step guide for you on the basics of Attributes usage:

http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help#37375

ask if you need help with it, otherwise try to follow it and create your own demo game.


Thanks for the responses. I'm using the off-line version.

That makes it easier.

However, when I go to the attributes tab for the 'player' object, there's no apparent way to make the attribute an integer. The program asks me to "enter the format string" when I either create the attribute or edit it.

There are attributes at the and there are status attributes. The top box is for status attributes, which determines what attributes will be displayed and how, but yu must first create te attrubute in the lower box and set it to be an integer there.

This might help:
https://github.com/ThePix/quest/wiki/Keeping-Score


Thanks! That seems to work.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums