Help with dice rolls and HP

Twine Version: 2.3.16
Story Format: 2.36.1

Hello there,

I’m in the process of setting up some health mechanics.
I’ve gotten healing and potion use down but I can’t quite figure out how to use dice mechanics to hurt my player.
I don’t want to predefine a weapons dmg. I’d like it to be a dice roll to immediately take from my hp pool.

Right now my attempt at this code is as follows. I have a meter health bar also to try and display .
So lets say my h$hp at the beginning of this fight is 60
I have a meter on my left side bar for HP that I would like to update in real time when dice roll occurs.

<meter @value="$hp" min="0" max="100"></meter>

For the actual dice roll I have…

You get <<linkappend "hit">>
<<set _rollresult1 to random(1, 6)>>
<<set $hp -= "_rollresult1">>

My $hp just says NaN once the dice it rolled and my meter doesn’t move.
What am I doing wrong here? I’m sure it’s something simple that I’m overlooking or I’m just straight up going about this the wrong way.

Any help would be amazing.


Quotes are for character values. For number values just drop the quotes.

1 Like

That did it. Thank you.

Is there anyway to get my meter to update live without having the change to another passage?

Quick update if anyone has my same question about a health meter that updates in real time.

I followed this page and it works great.