Poisoning the player (SOLVED)

1234676543224
07 Oct 2021, 22:53

Hello,
In one of my games I intend that the player can be possibly poisoned by an object like a giant viper. I tried to run a turn script which, every 10 turns, if the player object had the flag "poisoned", would be supposed to take one hitpoint away. Instead, it waits 10 turns and then takes away 1 hitpoint per turn continually. Can anyone help with this?


mrangel
08 Oct 2021, 09:20

If you show your code, we could probably tell you where the problem is.

However, from your description, I'd expect the turnscript to look something like this:

if (GetBoolean (game.pov, "poisoned")) {
  if (this.turns = 10) {
    this.turns = 1
    game.pov.health = game.pov.health - 1
  }
  else {
    this.turns = this.turns + 1
  }
}
else {
  // reset the turn counting if the player isn't poisoned
  this.turns = 0
}

1234676543224
08 Oct 2021, 13:18

Thank you, my problem has been solved.


mrangel
08 Oct 2021, 13:54

I figured it makes sense to make the turn counter an attribute of the turnscript rather than the player, because it's a little more organised. A lot of people don't seem to know you can do that; so figured it's good to point it out. this refers to the element the script belongs to; and you can still put attributes on it if it's a turnscript or a command. So it's a good place to store information related to a particular script.