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

How to create a HP current/Max Attribute

I was trying to create a attribute that would automatically determine a character's max HP, and then would allow an input for current HP, which would then be able to be put into a single attribute to be represented by a bar over a token. This is my current setup Max HP <input type="number" name="attr_Max_HP" value="@{Con}*4+@{LVL}*4" disabled="true"/> Current HP <input type="number" name="attr_Current_HP" /> This coding is working perfectly fine for me, but i wanted it to reflect it into a single "current/max" attribute I found this setup in a different post where the user said it would work, but I'm unsure how I could adapt it to fit with the formula I have for max HP. Current hp: <input type="number" name="attr_hp"> Max hp: <input type="number" name="attr_hp_max"> HP percentage: <input type="number" name="attr_hp-percent" disabled="disabled" value="round(@{hp} / @{hp|max})"> Any help is appreciated. 
1571687120

Edited 1571687271
GiGs
Pro
Sheet Author
API Scripter
If you want to have max and current attributes for use with a token bar, you have to use a single attribute. All attributes have a hidden _max property, and you can set that just the same way you set the current attribute. You could use  Current hp: <input type="number" name="attr_hp"/> Max hp: <input type="number" name="attr_hp_max" value="@{Con}*4+@{LVL}*4" disabled="true"/> The problem is token bars don't play nice with autocalc attributes. You are better of setting the max with a sheet worker. First the inputs: Current hp: <input type="number" name="attr_hp" value="" /> Max hp: <input type="number" name="attr_hp_max" value="" readonly/> Note the change from disabled to readonly. That means players cant manually alter the attribute, but sheet workers can.  And then you create a sheet worker to calculate the max attribute. If you dont have any sheet workers in your html, you need to first create a script block to contain it. Add the following to the end of your html: < script type = "text/worker" > </ script > All sheet workers you create go between the two script lines there. Now to create your hp_max worker: on ( "change:con change:lvl sheet:opened", function () { getAttrs ([ "Con" , "LVL" ], function (values) { var con = +values.Con || 0;       var lvl = +values.LVL || 0; var hits = (lvl + con) * 4; setAttrs ({ hp_max: hits }); }); }); Put this between the 2 script lines, save the sheet and you are good to go. You can consult the wiki to see how this works, if you have any questions ask away. It will set the max hop every time your con or lvl attributes change.
1571688592
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
GiGs said: IAll attributes have a hidden _max property, and you can set that just the same way you set the current attribute. I did not know that. I wonder if there's a problem I can aim this solution at.
1571689970
GiGs
Pro
Sheet Author
API Scripter
keithcurtis said: GiGs said: IAll attributes have a hidden _max property, and you can set that just the same way you set the current attribute. I did not know that. I wonder if there's a problem I can aim this solution at. Technically there's no connection between the current and max scores. For example, you can put text in either or both. It's meant for connected attributes (like current and max HPs, on token bars) but you don't have to use them that way. I'd be curious to see what problems you solve (or create, haha).
1571691643
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I dunno. It just felt like you said, "Here, Keith. Hold this hammer," and now I want to go find some nails.
That worked perfectly. Thanks so much for your help. I only wish there was a way for the current HP to increase at the same amount as the Max HP, for example if my max HP increased by 4, my current would automatically do the same, but then there would have to be a formula for the current which would not work out. I'm content right now with actually completing my character sheet, given that I just started learning Html coding on Saturday. Thanks again for all the help.
1571695546
Andreas J.
Forum Champion
Sheet Author
Translator
Marc L. said: That worked perfectly. Thanks so much for your help. I only wish there was a way for the current HP to increase at the same amount as the Max HP, for example if my max HP increased by 4, my current would automatically do the same, but then there would have to be a formula for the current which would not work out. I'm content right now with actually completing my character sheet, given that I just started learning Html coding on Saturday. Thanks again for all the help. I'm pretty sure that could be achieved with a sheetworker.
1571695731
GiGs
Pro
Sheet Author
API Scripter
It is possible to automate that, and more (like stop the current from going above max), but it's tricky because there might be changes you want to apply manually and its easy to not account for that and end up with attributes that are out of sync. For example, here's a worker that will change the current hp whenever the max changes (up or down), and will not raise the currenthp above the current max (so if already above the max, it will be reset): on("change:hp_max", function (event) {     getAttrs(["hp"], function (values) {         const hp = +values.hp || 0;         const oldmax = +event.previousValue || 0;         const newmax = +event.newValue || 0;         if (oldmax && newmax ) {             const change = newmax - oldmax;             const newhp = Math.min(hp + change, newmax);             setAttrs({                 hp: newhp             });         }     }); }); The if statement in the middle is to ensure it runs only when there's a valid oldmax and newmax value. But calculations like these are a little tricky, and depending on the way you run the game (are their temporary buffs, conditions that alter stats, etc)., we may need to think more carefully about the logic.
Yeah. Ultimately I'm thinking it's gonna be something where people will just need to make sure to update their hp on there own. There isn't alot of instances of temporary HP in my system, but it still seems like it could cause more issues than it would help. I actually had to delete out the whole thing, because I forgot that in my system it isn't always LVL*4. It varies based on the class you have chosen. So I need to add more info which won't be ready for my players at 8:00 tonight. Its a simply change in the formula and adding new fields for the multiplier so that it isn't just *4 it would be *lvl_mult essentially.
1571698990
GiGs
Pro
Sheet Author
API Scripter
That would be pretty easy to add when you're ready for it, just need an attribute to store the multiplier in. I assumed the name lvl_hp_mult here: on ( "change:con change:lvl change:lvl_h p_mult sheet:opened", function () { getAttrs ([ "Con" , "LVL", " lvl_h p_mult"], function (values) { var con = +values.Con || 0;       var lvl = +values.LVL || 0; var mult = +values. lvl_h p_mult || 1; var hits = (lvl + con) * mult; setAttrs ({ hp_max: hits }); }); });
Yeah. It will definitely be very easy to do, I just had alot going on for a halloween party this past weekend. Now I'm back at it. Thanks for the coding for it.
So I figure I will ask here instead of making a new forum page, just cause you've been very knowledgeable. I have made several fieldsets on the character sheet, but the two shown below don't seem to want to work. Any time someone tries to access the dropdown list within the fieldset, for any weapon other than the first one, it will immediately delete the entry. I'm wondering if the dropdown lists are not possible in a fieldset. <h2>Weapons</h2> <h4>Melee Weapons</h4> <fieldset class="repeating_melee_weapon">  <br> Weapon <input type="text" name="attr_MW" /> <br> Damage Type <select name="attr_DTM" class="DTM">     <option value = "1">Bludgeoning</option>     <option value = "2">Piercing</option>     <option value = "3">Slashing</option> </select> Specialty <select name="attr_SM" class="SM">     <option value = "1"></option>     <option value = "2">Backstabber</option>     <option value = "3">Backswing</option>     <option value = "4">Bleeding</option>     <option value = "5">Brace</option>     <option value = "6">Bullrush</option>     <option value = "7">Charge</option>     <option value = "8">Cleaving</option>     <option value = "9">Deadly</option>     <option value = "10">Disarm</option>     <option value = "11">Forceful</option>     <option value = "12">Flat-footed</option>     <option value = "13">Knockback</option>     <option value = "14">Knockdown</option>     <option value = "15">Parry</option>     <option value = "16">Binning</option>     <option value = "17">Reach</option>     <option value = "18">Reposition</option>     <option value = "19">Shield</option>     <option value = "20">Staggering</option>     <option value = "21">Sweep</option>     <option value = "22">Throwing</option>     <option value = "23">Trip</option>     <option value = "24">Two-Handed</option>     <option value = "25">Versatile</option>     <option value = "26">Weakening</option> </select> <br> <button type='roll' value='/roll @{DM} + @{DBM}' name='roll_DamageM'></button> Damage <select name="attr_DM" class="DM">     <option value = "1d4">1d4</option>     <option value = "1d6">1d6</option>     <option value = "1d8">1d8</option>     <option value = "1d10">1d10</option>     <option value = "1d12">1d12</option>     <option value = "2d8">2d8</option>     <option value = "2d10">2d10</option> </select> + <input type="number" name="attr_DBM" value="0" />  <br> <button type='roll' value='/roll ceil((@{DM} + @{DBM})/2)' name='roll_1/2_DamageM'></button> 1/2 Dmg  <br> <button type='roll' value='/roll 1d20 + @{AM}' name='roll_Attack'></button> Attack <input type="number" name="attr_AM" value="0" />  Crit Range <input type="number" name="attr_CM" value="20" max="20"/> <br> </fieldset> <br><br> <h4>Ranged Weapons</h4> <fieldset class="repeating_ranged_weapon">  <br> Weapon <input type="text" name="attr_RW" />  <br> Range <input type="number" name="attr_R" value="75" />ft       Damage Type <select name="attr_DTR" class="DTR">     <option value = "1">Bludgeoning</option>     <option value = "2">Piercing</option>     <option value = "3">Slashing</option> </select> Specialty <select name="attr_SR" class="SR">     <option value = "1"></option>     <option value = "2">Backstabber</option>     <option value = "3">Backswing</option>     <option value = "4">Bleeding</option>     <option value = "5">Brace</option>     <option value = "6">Bullrush</option>     <option value = "7">Charge</option>     <option value = "8">Cleaving</option>     <option value = "9">Deadly</option>     <option value = "10">Disarm</option>     <option value = "11">Forceful</option>     <option value = "12">Flat-footed</option>     <option value = "13">Knockback</option>     <option value = "14">Knockdown</option>     <option value = "15">Parry</option>     <option value = "16">Binning</option>     <option value = "17">Reach</option>     <option value = "18">Reposition</option>     <option value = "19">Shield</option>     <option value = "20">Staggering</option>     <option value = "21">Sweep</option>     <option value = "22">Throwing</option>     <option value = "23">Trip</option>     <option value = "24">Two-Handed</option>     <option value = "25">Versatile</option>     <option value = "26">Weakening</option> </select> <br> <button type='roll' value='/roll @{DR} + @{DBR}' name='roll_DamageR'></button> Damage <select name="attr_DR" class="DR">     <option value = "1d4">1d4</option>     <option value = "1d6">1d6</option>     <option value = "1d8">1d8</option>     <option value = "1d10">1d10</option>     <option value = "1d12">1d12</option>     <option value = "2d8">2d8</option>     <option value = "2d10">2d10</option> </select> + <input type="number" name="attr_DBR" value="0" />  <br> <button type='roll' value='/roll ceil((@{DR} + @{DBR})/2)' name='roll_1/2_DamageR'></button> 1/2 Dmg  <br> <button type='roll' value='/roll 1d20 + @{AR}' name='roll_AttackR'></button> Attack <input type="number" name="attr_AR" value="0" />  Crit Range <input type="number" name="attr_CR" value="20" max="20"/> <br><br> </fieldset> 
1572311992
GiGs
Pro
Sheet Author
API Scripter
It's most likely because of the second underscore in the names: repeating_melee_weapon I cant remember if its documented or not, but I believe repeating sections with extra underscores don't work. You can use extra underscores in the individual fieldnames, just not in the repeating_ bit.
It is documented, but it is mentioned in passing. First paragraph, next-to-last sentence: <a href="https://wiki.roll20.net/Building_Character_Sheets#Repeating_Sections" rel="nofollow">https://wiki.roll20.net/Building_Character_Sheets#Repeating_Sections</a>
1572332565
GiGs
Pro
Sheet Author
API Scripter
So it is. I've edited the page to make it a bit more noticeable.
Thanks guys. I don't know how I keep missing this giant notifications when reading through. Glad you guys are so helpful though, and not snarky about it. It is very appreciated. I will edit this later and see if it resolves the issue. If not, I suppose I'll be back. Lol
Back at it again. lol So I removed the underscore and now it does work towards adding extra weapons. The problem now is that I would like to be able to make some macros which use the attack bonus ability that is a part of the weapon and I can't seem to get it to work. I have tried to enter /roll 1d20+@{AM1} but it says no such attribute exists. I have tried to make a new character and enter nothing but the weapon info, but no attributes appear. I have tried to just click and drag the button that's on the sheet into the macros bar, but that doesn't seem to work either. The button works when I click it on the sheet, but I'm trying to avoid having to pull up the character sheet for every attack. Here is the code again. &lt;h2&gt;Weapons&lt;/h2&gt; &lt;h4&gt;Melee Weapons&lt;/h4&gt; &lt;fieldset class="repeating_meleeweapon"&gt;&nbsp; &lt;br&gt; Weapon &lt;input type="text" name="attr_MW" /&gt; &lt;br&gt; Damage Type &lt;select name="attr_DTM" class="DTM"&gt; &nbsp; &nbsp; &lt;option value = "1"&gt;Bludgeoning&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "2"&gt;Piercing&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "3"&gt;Slashing&lt;/option&gt; &lt;/select&gt; Specialty &lt;select name="attr_SM" class="SM"&gt; &nbsp; &nbsp; &lt;option value = "1"&gt;&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "2"&gt;Backstabber&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "3"&gt;Backswing&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "4"&gt;Bleeding&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "5"&gt;Brace&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "6"&gt;Bullrush&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "7"&gt;Charge&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "8"&gt;Cleaving&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "9"&gt;Deadly&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "10"&gt;Disarm&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "11"&gt;Forceful&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "12"&gt;Flat-footed&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "13"&gt;Knockback&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "14"&gt;Knockdown&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "15"&gt;Parry&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "16"&gt;Binning&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "17"&gt;Reach&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "18"&gt;Reposition&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "19"&gt;Shield&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "20"&gt;Staggering&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "21"&gt;Sweep&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "22"&gt;Throwing&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "23"&gt;Trip&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "24"&gt;Two-Handed&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "25"&gt;Versatile&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "26"&gt;Weakening&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;button type='roll' value='/roll @{DM} + @{DBM}' name='roll_DamageM'&gt;&lt;/button&gt; Damage &lt;select name="attr_DM" class="DM"&gt; &nbsp; &nbsp; &lt;option value = "1d4"&gt;1d4&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "1d6"&gt;1d6&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "1d8"&gt;1d8&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "1d10"&gt;1d10&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "1d12"&gt;1d12&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "2d8"&gt;2d8&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "2d10"&gt;2d10&lt;/option&gt; &lt;/select&gt; + &lt;input type="number" name="attr_DBM" value="0" /&gt;&nbsp; &lt;br&gt; &lt;button type='roll' value='/roll ceil((@{DM} + @{DBM})/2)' name='roll_1/2_DamageM'&gt;&lt;/button&gt; 1/2 Dmg&nbsp; &lt;br&gt; &lt;button type='roll' value='/roll 1d20 + @{AM}' name='roll_Attack'&gt;&lt;/button&gt; Attack &lt;input type="number" name="attr_AM" value="0" /&gt;&nbsp; Crit Range &lt;input type="number" name="attr_CM" value="20" max="20"/&gt; &lt;br&gt; &lt;/fieldset&gt;
1572803250

Edited 1572803273
Andreas J.
Forum Champion
Sheet Author
Translator
Marc L. said: I have tried to enter /roll 1d20+@{ AM1 } but it says no such attribute exists. &lt;button type='roll' value='/roll 1d20 + @{ AM }' name='roll_Attack'&gt; &lt;input type="number" name="attr_ AM " value="0" /&gt; So do you only have a typo in your post, or do you have the button set as " AM1 " on the character sheet as well? bc it looks correct in the code.
The button on the character sheet is AM. I was typing it as AM1 for the macro because I thought that's what you had to do whenever you were adding an attribute from a repeating section, in order to make it select the first entry of the repeating section. I think I had also tried just using AM before as well and it still was not working. Basically I want people to be able to enter a sword and then have one macro for attacking with their sword and then have a second weapon of a mace and be able to enter a macro for when they attack with the mace. Those can't both be AM right?
1572809602

Edited 1572809657
GiGs
Pro
Sheet Author
API Scripter
If its in a repeating section, you have to use the repeating section name, and some way of identifying the row, If the repeating section is called&nbsp; repeating_meleeweapon , then this would get the first item: @{repeating_meleeweapon_$0_AM} This would get the second item @{repeating_meleeweapon_$1_AM} It uses programmer numbering, where the first item is 0, the second is 1, and so on.
Thanks so much. I'll mess with that now. I'm seeing why I should have just posted that hear though. Going back to the HP multiplier thing. I am trying to fix the info for that now and it doesn't seem to want to work. Here is what I currently have written in the character sheet for the info. HP Multiplier &lt;select name="attr_HPM" class="HPM"&gt; &nbsp; &nbsp; &lt;option value = "0"&gt;&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "5"&gt;x5&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "6"&gt;x6&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "7"&gt;x7&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "8"&gt;x8&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "9"&gt;x9&lt;/option&gt; &lt;/select&gt; Current hp: &lt;input type="number" name="attr_hp" value="" /&gt; Max hp: &lt;input type="number" name="attr_hp_max" value="" readonly/&gt; &lt;br&gt; EP Multiplier &lt;select name="attr_EPM" class="EPM"&gt; &nbsp; &nbsp; &lt;option value = "0"&gt;&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "1"&gt;x1&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "2"&gt;x2&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "3"&gt;x3&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "4"&gt;x4&lt;/option&gt; &nbsp; &nbsp; &lt;option value = "5"&gt;x5&lt;/option&gt; &lt;/select&gt; Current ep: &lt;input type="number" name="attr_ep" value="" /&gt; Max ep: &lt;input type="number" name="attr_ep_max" value="" readonly/&gt; At the end of the sheet I have written the following &lt;script type="text/worker"&gt; on("change:con change:lvl change:hpm sheet:opened", function() { &nbsp; &nbsp;getAttrs(["Con", "LVL" , "HPM"], function(values) { &nbsp; &nbsp; &nbsp; var con = +values.Con || 0; &nbsp; &nbsp; &nbsp; var lvl = +values.LVL || 0; &nbsp; &nbsp; &nbsp; var hpm = +values.HPM || 0; &nbsp; &nbsp; &nbsp; var hits = lvl*hpm + con * 4; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hp_max: hits &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp;}); on("change:wis change:lvl change: epm sheet:opened", function() { &nbsp; &nbsp;getAttrs(["Wis", "LVL" , "EPM"], function(values) { &nbsp; &nbsp; &nbsp; var wis = +values.Wis || 0; &nbsp; &nbsp; &nbsp; var lvl = +values.LVL || 0; &nbsp; &nbsp; &nbsp; var epm = +values.EPM || 0; &nbsp; &nbsp; &nbsp; var hits = lvl*epm + Wis * 4; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ep_max: hits &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp;}); }); &lt;/script&gt;
The macro for the weapon attacks worked perfectly. Thanks again!
1572851354
GiGs
Pro
Sheet Author
API Scripter
The workers look properly constructed. The first thing to check. This line on("change:wis change:lvl change: epm sheet:opened", function() { Has a space where it shouldnt be, between change and epm. Is that a copy paste error, or is your code like that? It should be on("change:wis change:lvl change:epm sheet:opened", function() {
1572851855

Edited 1572851893
GiGs
Pro
Sheet Author
API Scripter
Found the culprit: your first worker isn't properly closed. It's missing an }); The code should be on("change:con&nbsp;change:lvl&nbsp;change:hpm&nbsp;sheet:opened",&nbsp;function&nbsp;()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;getAttrs(["Con",&nbsp;"LVL",&nbsp;"HPM"],&nbsp;function&nbsp;(values)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;con&nbsp;=&nbsp;+values.Con&nbsp;||&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;lvl&nbsp;=&nbsp;+values.LVL&nbsp;||&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;hpm&nbsp;=&nbsp;+values.HPM&nbsp;||&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;hits&nbsp;=&nbsp;lvl&nbsp;*&nbsp;hpm&nbsp;+&nbsp;con&nbsp;*&nbsp;4; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hp_max:&nbsp;hits &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}); }); // &lt;---- you were missing this set of brackets and semi-colon }); on("change:wis&nbsp;change:lvl&nbsp;change:epm&nbsp;sheet:opened",&nbsp;function&nbsp;()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;getAttrs(["Wis",&nbsp;"LVL",&nbsp;"EPM"],&nbsp;function&nbsp;(values)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;wis&nbsp;=&nbsp;+values.Wis&nbsp;||&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;lvl&nbsp;=&nbsp;+values.LVL&nbsp;||&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;epm&nbsp;=&nbsp;+values.EPM&nbsp;||&nbsp;0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;hits&nbsp;=&nbsp;lvl&nbsp;*&nbsp;epm&nbsp;+&nbsp;Wis&nbsp;*&nbsp;4; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ep_max:&nbsp;hits &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}); });
Those fixes worked. Also needed to change the Wis for the "var hits" line of ep into a lower case w. Unfortunately it is still not calculating the lvl * epm&nbsp; or lvl * hpm portion. Based on our other conversations, this is because level is an autocalculated field. So in an attempt to fix that, I've written the following code Level &lt;input type="number" name="attr_lvl" value="" readonly/&gt; Total EXP &lt;input type="number" name="attr_total_EXP" value="300"/&gt; The sheet worker at the end then reads as follows, based on what I have determined from the sheet worker scripts I read on the wiki. on("change:total_exp", function() { &nbsp; &nbsp;getAttrs(["total_EXP"], function(values) { &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lvl: Math.floor ((values.total_exp - 200)/100) &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp;}); }); Yet again I am completely stuck. Leaves me with a blank space for my level on the character sheet, so clearly I am inputting something incorrectly, but I don't see anything wrong with the code, compared to what was in the wiki. I feel like if this part is figured out, it should be a snowball effect that gets the other working as well.
1572933148
GiGs
Pro
Sheet Author
API Scripter
You';re correct that level needs to not be an autocalc. One problem i notice is that the last total_exp is in lower case, but the one in get Attrs is not. I'm not sure if that matters actually. The bigger problem is likely that the value for XP hasn't been converted into a number. Every attribute on the character sheet is a text value, a string in programming terms. Even if it looks like a number, as far as the code is concerned, its a string of letters. You need to convert it into a number to perform arithmetic with, and above codes do that.&nbsp;There's two common ways to do this: let EXP = parseInt(values.EXP) || 0; or let EXP = +values.EXP || 0; So try this on("change:total_exp", function() { &nbsp; &nbsp;getAttrs(["total_EXP"], function(values) { &nbsp; &nbsp; &nbsp; let exp = +values. total_EXP ||0; &nbsp; &nbsp; &nbsp; let lvl = Math.floor((exp-200)/100); &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lvl: lvl &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp;}); }); One final thing: that level calculation looks a bit suspect to me. If the XP is below 200, you'll have a negative level. Can you list the XP progression so we can check the formula is right?
That still wasn't working for some reason. I edited the code of the cell itself to be "totalexp" without any capitalization whatsoever, and it fixed the issue. Level, HP and EP are now calculating correctly. This is a game where players spend experience as they level up, so first level has 300 experience and characters level up every additional 100 experience. So the formula is correct. Thanks for the double check there though. Now I'm running into an issue where the remaining experience isn't being calculated correctly anymore, because the totalexp value has been converted and no longer works for the remaining experience formula. *sigh* so it's time to rewrite that from an auto-calculated field into a sheet worker formula. Wish me well. This may cause a massive chain effect, really hoping it doesn't.
This is the formula I'm about to convert.&nbsp; Current EXP &lt;input type="number" name="attr_current_EXP" value="@{total_EXP} - ( @{Talents_known}*25 + ( @{Str} + @{Dex} + @{Con} + @{Int} + @{Wis} + @{Cha} + @{Feats_known} )*10 + ( @{MDB} + @{CB} + @{SDB} + @{SAB} + @{IB} )*5 + ( @{Ath_Ranks} + @{Acr_Ranks} + @{Ste_Ranks} + @{The_Ranks} + @{App_Ranks} + @{Arc_Ranks} + @{Cra_Ranks} + @{Cul_Ranks} + @{His_Ranks} + @{Intu_Ranks} + @{Nat_Ranks} + @{Per_Ranks} + @{Rel_Ranks} + @{Spe_Ranks} + @{Sur_Ranks} + @{Perf_Ranks})*2)" disabled="true"/&gt; Lord have mercy. lol
1572961853
GiGs
Pro
Sheet Author
API Scripter
Marc L. said: That still wasn't working for some reason. I edited the code of the cell itself to be "totalexp" without any capitalization whatsoever, and it fixed the issue.&nbsp; weird. It's good practice to use all lower case letters for attribute names, but I dont understand why it was necessary in this case. But if it works, it works :) For that formula, remember that none of the attributes mentioned there can be autocalcs, If any are, fix them first.
BOOM!!!! That went perfectly. I went through and changed all of the "attr_" names to be lowercase and removed any underscores in the titles as well. Then wrote the code and it is now all working perfectly. I know feel confident to rewrite the other codes as well to begin making the API script to make autospending of EP work in the other sections. This feels like my greatest success. lol. Thank you so much.
1572966922
GiGs
Pro
Sheet Author
API Scripter
Yay :) Before you make the API script, check out chatSetAttr. It may already do what you need.
Thanks for the heads up. I tried to edit some other things and it was not working, so I'm gonna take a break for now. I'll definitely check it out the chatSetAttr when I get to that step.