[英]How to stop my hp from increasing when i press hp up button and out of skillpoints
So i have a working function but its still going when i have 0 skill points http://prntscr.com/ns4tfx http://prntscr.com/ns4tld http://prntscr.com/ns4tse as you can see it keeps going up. 所以我有一个工作功能,但是当我有0个技能点时它仍然会继续工作,如您所见,它一直在不断发展。http: //prntscr.com/ns4tfx http://prntscr.com/ns4tld起来 it shouldn't do anything if skillpoints is at 0 如果技能点为0,则不应执行任何操作
I've tried messing around with if statements to fix it but no luck 我试图弄乱if语句来解决它,但没有运气
Here's my Javascript code: 这是我的Javascript代码:
function HitPointsup(){
if (SkillPoints>0 && rebirths >=1)
SkillPoints = SkillPoints - 1;
HitPoints = HitPoints + 10;
document.getElementById('SkillPoints').innerHTML = SkillPoints;
document.getElementById("HitPoints").innerHTML = HitPoints;
Here's my html code: 这是我的html代码:
Skill Tree SP:<span id="SkillPoints1">0</span>
<br />
<br />
<button id="HitPointsup" onclick="HitPointsup()">Hp
up</button> <button id="SkillPoints2" onclick="Mp up()">Mp
up</button>
<br />
<button id="SkillPoints3" onclick="Hp regen()">Hp
regen</button>
I expect the hp up button to only work when i have skill points to spend ( i thought putting if(SkillPoints >0) would be enough). 我希望hp up按钮仅在我有技能要花费的时候才起作用(我认为放置if(SkillPoints> 0)就足够了)。 my acual results is you can keep pressing the button and hp keeps going up by 10. skill points stay at 0 tho no negative numbers there. 我的最终结果是,您可以继续按该按钮,并且hp继续上升10。技能点保持在0或那里没有负数。
You are making a 'single line if', that means that only the first line below the if (SkillPoints>0 && rebirths >=1) is being verified. 您正在制作“单行if”,这意味着仅对if(技能点数> 0 &&重生> = 1)下的第一行进行验证。 The other values are getting updated as-well. 其他值也正在更新。 Try to user brackets like: 尝试使用如下方括号:
function HitPointsup(){
if (SkillPoints>0 && rebirths >=1){
SkillPoints = SkillPoints - 1;
HitPoints = HitPoints + 10;
}
document.getElementById('SkillPoints').innerHTML = SkillPoints;
document.getElementById("HitPoints").innerHTML = HitPoints;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.