Hi there I’m using Sugarcube version 2.2.1 and I’m running into a problem with a health bar displaying incorrectly in a bottom bar in my PassageFooter.
I’m using HiEv’s healthbar code (THANK-YOU!!) and the code in my PassageFooter is this:
> /*The exclamation point below means that any passage WITHOUT the bbar tag WILL display the text in the div id below*/
> <<if !tags().includes("bbar")>>
> <div id="bottombar"><div id="bbblock"><div id="bbtext">
> <div id="hzhealthbarbkg" class="hzbarbkg">
> <div id="hzhealthbar" class="hzbar"></div>
> </div>
> </div>
> <</if>>
My problem passage [[riddle display]] looks like this:
JAVASCRIPT GETTING THE HEALTHBAR TO RENDER AT START OF PASSAGE (???)
<<script>>$(document).one(':passagerender', function (ev) {
Health2(50, 50, "hzhealthbar", true, ev.content);
});<</script>>
LOSE HEALTH BUTTON:
<<button "Trying to modify the bottom health">>
<<set $CurHP2 = $CurHP2-10>>
<<run Health2($CurHP2, $MaxHP, "hzhealthbar", true)>>
<</button>>
[[riddle display]] THIS LINKS BACK TO THE SAME PASSAGE
The health bar works fine in the sense that when I press the button it animates and loses health without navigating to another passage (which is awesome). BUT, I’ve noticed that if I go back to the same passage, the healthbar resets to full health (50) because of the Javascript passagerender which is restoring it incorrectly to 50 at the start of the passage when in reality the underlying health variable (CurHP) IS being changed correctly.
No problem, I thought, I’ll just change the 50 in the script to be a variable ($CurHP), but whenever I try this it causes an error and Twine says $CurHP is undefined (It definitely IS defined in my StoryInit, but I suspect there’s a Javascript usage limitation going on here or something?
So yeah, I’m sorry this is surely something stupidly simple but it’s sure beyond me! Any help is very appreciated and I’m so sorry for my ignorance!