简体   繁体   English

当我按下hp up按钮并超出技能点时如何阻止hp增大

[英]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 &nbsp; &nbsp; SP:<span id="SkillPoints1">0</span>
                <br />
                <br />
                <button id="HitPointsup" onclick="HitPointsup()">Hp 
up</button> &nbsp; <button id="SkillPoints2" onclick="Mp up()">Mp 
up</button>
                <br />
                <button id="SkillPoints3" onclick="Hp regen()">Hp 
regen</button>
                &nbsp;

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.

相关问题 重生= 1时如何停止法力增加和生命值增加 - How to stop mana increase and hp increase when rebirths=1 如何在网站加载时停止播放 ccs 关键帧,仅在我按下按钮时播放 - how to i stop the ccs keyframe from playing when the website loads and only play when i press the button 按下Enter键时如何停止触发按钮 - how to stop a button from being fired when press enter 我在这里用 hp bar 解决了我的问题 - I am stuck fixing my issue here with an hp bar "if 语句不起作用 - 当技能点低于 0 时脚本不会停止" - if statement does not work - script doesn't stop when skillpoints are below 0 反应:当我按下按钮时缓慢滚动页面,当我按下另一个按钮时停止滚动 - React: Slowly scrolling page when i press button and stop scrolling when i press another button 如何在 HP LoadRunner 脚本中使用 JavaScript - How to use JavaScript in your HP LoadRunner scripts 如何获得不透明性以停止按下按钮的褪色? - How do I get the opacity to stop fading with a button press? 在玩游戏时,如何阻止我的网站通过箭头键上下滚动? - How do I stop my website from scrolling up and down with the arrow keys when playing games? 我希望我的动画在屏幕上水平移动,并在按下停止按钮后停止 - I want my animation to travel horizontally across the screen and stop once i press the stop button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM