Updating an enemy's health (status attribute) in simple combat

Grids
07 Jan 2022, 06:26

I am trying to create extremely simple combat. I can get the player's health to update in the status pane but not the enemy's health (updating the number) in the status pane. I have read over lots on attributes etc but I am a confused noob. The first hit is a guarantee. After that I want it to be chance based and I would like it to update in the status...any thoughts about what I am doing wrong.

firsttime {
  dictionary add (game.statusattributes, "EnemyHealth", "Enemy Health:100")
  msg ("You punch the strange entity. The holographic creature swirls with broken code as it is hit.")
  
}
otherwise {
  msg ("You fight.")
  result = DiceRoll("1d6")
  if (result>3) {
    msg ("You punch the entity and it cowers with pain.")
    game.EnemyHealth = game.EnemyHealth - 10
    if (game.EnemyHealth < 1) {
      MakeObjectVisible (Dead spectre)
      MakeObjectInvisible (spectre)
    }
  }
  else {
    msg ("The creature dodges your fist and spits data at you. Your head swirls in pain.")
    player.health = player.health - 10
  }
}```

mrangel
07 Jan 2022, 09:52

You've set it to display the string "Enemy Health:100" in the status pane. If you want it to display the value of game.EnemyHealth, the string in the firsttime block should be "Enemy Health: !" (the ! gets replaced by the current value of the attribute each turn).

You might also need to set game.EnemyHealth to its initial value at some point, if you haven't done that already.


Grids
09 Jan 2022, 03:27

Perfect. Thank you so much!