Thank you and Josh for the info taking the time to respond, and especially the detailed steps you’ve given! Appreciate the help! I think I’m understanding it a bit more, but I’m still not quite getting it to work right. I can show everything I have for this in a more complete form. From a new game, trying to get the code right.
:: Story Javascript [script]
/*-----------------------------------------------------------------------------------------*/
/* HiEv Status Bars for player HP and Stamina */
/*-----------------------------------------------------------------------------------------*/
window.Health = function (pCurHp, pMaxHp, BarID, Horizontal, Container) {
if (Container == undefined) {
Container = document;
}
var HP = parseInt((pCurHp / pMaxHp) * 100).clamp(0, 100);
var BarElement = $(Container).find("#" + BarID);
if (Horizontal) {
BarElement.css({ width: HP + "%" });
} else {
BarElement.css({ height: HP + "%" });
}
var col = "hsl(" + (Math.floor(HP * 2.6) - 20) + ", 100%, 50%)";
BarElement.css("background-color", col);
BarElement.attr("title", pCurHp + "/" + pMaxHp + " Health");
$(Container).find("#" + BarID + "bkg").attr("title", pCurHp + "/" + pMaxHp + " Health");
};
window.Stamina = function (pCurSta, pMaxSta, BarID, Horizontal, Container) {
if (Container == undefined) {
Container = document;
}
var ST = parseInt((pCurSta / pMaxSta) * 100).clamp(0, 100);
var BarElement = $(Container).find("#" + BarID);
if (Horizontal) {
BarElement.css({ width: ST + "%" });
} else {
BarElement.css({ height: ST + "%" });
}
BarElement.attr("title", pCurSta + "/" + pMaxSta + " Stamina");
$(Container).find("#" + BarID + "bkg").attr("title", pCurSta + "/" + pMaxSta + " Stamina");
};
/*-----------------------------------------------------------------------------------------*/
/* Enemy Health Bar */
/*-----------------------------------------------------------------------------------------*/
window.EneHealth = function (eCurHp, eMaxHp, BarID, Horizontal, Container) {
if (Container == undefined) {
Container = document;
}
var EHP = parseInt((eCurHp / eMaxHp) * 100).clamp(0, 100);
var BarElement = $(Container).find("#" + BarID);
if (Horizontal) {
BarElement.css({ width: EHP + "%" });
} else {
BarElement.css({ height: EHP + "%" });
}
var cole = "hsl(" + (Math.floor(EHP * 2.6) - 20) + ", 100%, 50%)";
BarElement.css("background-color", cole);
BarElement.attr("title", eCurHp + "/" + eMaxHp + " Health");
$(Container).find("#" + BarID + "bkg").attr("title", eCurHp + "/" + eMaxHp + " Health");
};
/*-----------------------------------------------------------------------------------------*/
/* Skills Function */
/*-----------------------------------------------------------------------------------------*/
window.UseSkill = function (ID) {
/* Lookup the relevent setup object */
const skill = setup[ID];
// Check if the player has enough stamina to use the skill
if (skill.staCost && skill.pCurSta < skill.staCost) {
alert("You are too tired to do that!");
return;
}
// Generate random damage
var randomDamage = Math.floor(Math.random() * (skill.maxDamage - skill.minDamage + 1) + skill.minDamage);
eCurHp -= randomDamage;
alert("You use " + skill.sname + " and dealt " + randomDamage + " damage to the enemy!");
for (const [skill, properties] of Object.entries(pSkills)) {
if (properties.isOnCooldown) {
properties.cooldown--;
if (properties.cooldown <= 0) {
properties.isOnCooldown = false;
}
}
}
// Call the enemy attack function
EnemyAttack();
}
// Define the enemy attack function
function EnemyAttack(){
// check if the turn has been passed and the player's health is greater than 0
if(State.variables.turns > 0 && pCurHp > 0) {
var enemyDamage = Math.floor(Math.random() * (20 - 10 + 1) + 10);
pCurHp -= enemyDamage;
alert("The enemy attacks and dealt " + enemyDamage + " damage to you!");
}
}
window.EnemyAttack = EnemyAttack;
:: StoryInit
<<set $pCurHp to 100>>
<<set $pMaxHp to 100>>
<<set $pCurSta to 100>>
<<set $pMaxSta to 100>>
<<set $eCurHp to 1>>
<<set $eMaxHp to 1>>
<<set $eneAtk = {
"minDamage" : 4,
"maxDamage" : 8,
}>>
/* Used for handling player abilities */
<<set $pSkills = []>>
<<set setup.Smash = {
"sname": "Smash",
"minDamage": 5,
"maxDamage": 12,
"staCost": 5,
"cooldown": 1,
"applyRandomDamage": true,
" isOnCooldown": false,
}>>
<<set setup.Fireball = {
"sname": "Fireball",
"minDamage": 10,
"maxDamage": 20,
"staCost": 20,
"cooldown": 4,
"applyRandomDamage": true,
" isOnCooldown": false,
}>>
<<set $pSkills.push("Smash")>>
<<set $pSkills.push("Fireball")>>
:: Start
<<set $eCurHp to 25>>
<<set $eMaxHp to 25>>
[[BattleTest]]
:: BattleTest
Health $pCurHp
<div id="healthbarbkg" class="hpbarbkg"><div id="healthbar" class="hpbar"></div></div>
<<script>>$(document).one(':passagerender', function (ev) {
Health(State.variables.pCurHp, State.variables.pMaxHp, "healthbar", true, ev.content);
});<</script>>
Stamina $pCurSta
<div id="staminabarbkg" class="stabarbkg"><div id="staminabar" class="stabar"></div></div>
<<script>>$(document).one(':passagerender', function (ev) {
Stamina(State.variables.pCurSta, State.variables.pMaxSta, "staminabar", true, ev.content);
});<</script>>
Enemy Health $eCurHp
<div id="enemybarbkg" class="enebarbkg"><div id="enemybar" class="enebar"></div></div>
<<script>>$(document).one(':passagerender', function (ev) {
EneHealth(State.variables.eCurHp, State.variables.eMaxHp, "enemybar", true, ev.content);
});<</script>>
<<nobr>>
<div class="row">
<<for _skill range $pSkills>>
<<capture _skill>>
<<link "setup[_skill].sname">><<run UseSkill(_skill)>><</link>>
<</capture>>
<br>
<</for>>
</div>
<</nobr>>
<<link "Refresh">><<script>>state.display(state.active.title, null, "back")<</script>><</link>>
Then the stylesheet, since it’s used for the HP/Stamina bars
:: stylesheet
.row {
display: flex;
flex-direction: row;
}
.row:after {
content: "";
display: table;
clear: both;
}
/* Health and Stamina Bars */
.hpbarbkg {
position: relative;
height: 15px;
width: 100%;
background-color: #111;
background-image: linear-gradient(to right, rgba(68, 68, 68, 0.5), rgba(34, 34, 34, 0.5) 5px), linear-gradient(to bottom, rgba(68, 68, 68, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to left, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px), linear-gradient(to top, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px);
border-radius: 10px;
z-index: 10;
visibility: visible;
}
.hpbar {
position: absolute;
bottom: 0px;
left: 0px;
height: 15px;
background-color: transparent;
background-image: linear-gradient(to left, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to top, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to right, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px), linear-gradient(to bottom, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px);
border-radius: 10px;
z-index: 20;
transition: width ease 1s, background-color ease 1s;
}
.stabarbkg {
position: relative;
height: 15px;
width: 100%;
background-color: #111;
background-image: linear-gradient(to right, rgba(68, 68, 68, 0.5), rgba(34, 34, 34, 0.5) 5px), linear-gradient(to bottom, rgba(68, 68, 68, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to left, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px), linear-gradient(to top, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px);
border-radius: 10px;
z-index: 10;
visibility: visible;
}
.stabar {
position: absolute;
bottom: 0px;
left: 0px;
height: 15px;
background-color: transparent;
background-image: linear-gradient(to left, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to top, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to right, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px), linear-gradient(to bottom, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px);
border-radius: 10px;
z-index: 20;
transition: width ease 1s, background-color ease 1s;
}
#staminabar {
background-image: linear-gradient(to left, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to top, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to right, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px), linear-gradient(to bottom, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px), radial-gradient( circle at bottom right, orange, orange 60% );
}
/* Enemy Health Bar */
.enebarbkg {
position: relative;
height: 15px;
width: 100%;
background-color: #111;
background-image: linear-gradient(to right, rgba(68, 68, 68, 0.5), rgba(34, 34, 34, 0.5) 5px), linear-gradient(to bottom, rgba(68, 68, 68, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to left, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px), linear-gradient(to top, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px);
border-radius: 10px;
z-index: 10;
visibility: visible;
}
.enebar {
position: absolute;
bottom: -3px;
left: -2px;
height: 15px;
background-color: transparent;
background-image: linear-gradient(to left, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to top, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 5px), linear-gradient(to right, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px), linear-gradient(to bottom, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 5px);
z-index: 20;
border-radius: 10px;
transition: width ease 1s, background-color ease 1s;
}
It tosses the error: Error: <>: bad evaluation: eCurHp is not defined.
So, I’m not sure how to properly let it access that variable in this situation. I’ve tried a couple different ways I’ve seen posted about about initializing the variable in the javascript section to see if that works. But haven’t gotten anything to work for me yet.