Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Combat API assistance

Hello I am pretty new to scripting and needs some assistance. I adopted Stephan H's combat api from <a href="https://app.roll20.net/forum/post/540414/script-4e" rel="nofollow">https://app.roll20.net/forum/post/540414/script-4e</a>... and made some changes to better match my gameplay/style. I added monitoring of the target's HP and TempHP (which are bars 1 and 2) and adjusting them with incoming damage. I also added changing states for bloodied and dead. Everything works fine on when working through the script. But if i change the bar values from any other script or manually, it fails to modify the HP/TempHP and i get this error from the sandbox: For reference, the error message generated was: /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function f(a){throw a;}var j=v ^ Error: Firebase.update failed: First argument contains NaN in property 'bar1_value' at Error (&lt;anonymous&gt;) at Aa (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:9:186) at Aa (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:196) at za (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:8:468) at Da (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:392) at G.W.update (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:128:318) at TrackedObj._doSave ( If i refresh the sandbox and campaign page, it works fine without issue. Any ideas? Here is my script: <a href="https://gist.github.com/69e25860ebf2f3e0a129.git" rel="nofollow">https://gist.github.com/69e25860ebf2f3e0a129.git</a>
It's probably line 149: targetenemytoken.set("bar1_value", parseInt(setenemyhp)); setenemyhp only ever gets set if TemporaryHP &gt; 0, so if TemporaryHP &lt;= 0 (or if TermporaryHP is NaN, undefined, or anything else which doesn't compare greater than zero) then parseInt(setenemyhp) will be parseInt(undefined), which is NaN. Setting setenemyhp to something reasonable in the else case (or at the top of the function) should fix this.
Manveti, thanks for that! I didn't even notice this. I added a var setenemyhp = parseInt(enemyhp) to line 145 which fixes that issue. I don't get the error anymore. But if i use any other script to change the hp manually, the script does not update the bars. It tells me the damage but the hp doesn't move at all
Nevermind, i figured it out...i fix i used output unchanged hp and var setenemyhp = parseInt(enemyhp) instead at lin 145 fixes it. Thanks for all your help! Nirav