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

setAttrs() just not working on _max attributes

I have, in my Sheet Worker Script, formulas that update the maximum number of Vitality Points and Magic Points a character has. const calcVpMax = <formula> const calcMpMax = <formula> console.log confirms that the value being calculated by the formula is correct. Then I'm calling a big old setAttrs() function, involving many variables that are  updating correctly ... but these two are not. setAttrs({     ...     vp_max: calcVpMax,     mp_max: calcMpMax }); I have, for each variable, two places on the character sheet where it's supposed to be displayed (and isn't updating when setAttrs() runs):                              < input   type = "number"   name = "attr_foo_vp_max"   value = "@{vp_max}"   disabled = "true"   />                              < input   type = "number"   name = "attr_foo_mp_max"   value = "@{mp_max}"   disabled = "true"   />                              < input   type = "number"   name = "attr_foo_vp_max_2"   value = "@{vp_max}"   disabled = "true"   />                              < input   type = "number"   name = "attr_foo_mp_max_2"   value = "@{mp_max}"   disabled = "true"   /> I don't actually know whether the problem is in the setAttrs() function, or in the display of the variables in the above inputs after the fact. But either way, I'm stumped.
Try changing disabled="true" to readonly .
Rabulias said: Try changing disabled="true" to readonly . OK - I tried that. It made those displays show up blank rather than persistently displaying their initial default values.
1587005180

Edited 1587005213
You may need to post more of the code, and probably someone like GiGs or The Aaron will help you with the code. What I do know is that sheetworkers cannot affect disabled fields; disabled fields are only for autocalculated fields. Autocalc fields are not very flexible and you probably should avoid them now that we have sheetworkers available. Also, I know to make copious use of console.log() commands and check your browser console to check values throughout your functions.
1587008381
GiGs
Pro
Sheet Author
API Scripter
As Rabulias says, sheet workers cant update disabled attributes. Also I notice something weird about your attribute names: <input type="number" name="attr_foo_vp_max" value="@{vp_max}" disabled="true" /> <input type="number" name="attr_foo_mp_max" value="@{mp_max}" disabled="true" /> <input type="number" name="attr_foo_vp_max_2" value="@{vp_max}" disabled="true" /> <input type="number" name="attr_foo_mp_max_2" value="@{mp_max}" disabled="true" /> the existence of foo_vp_max_2 makes me wonder if something is iffy here. In roll20 attributes that end in _max are special. But the fact you have ones ending in _max_2 has me scratching my head. But the first thing to check is: are any of the attributes used in this calculation autocalc fields? That is, ones that have a calculation that is not made by a sheet worker. Things like <input type="number" name="attr_something" value="@{some}+@{thing}" disabled="true" /> sheet workers do not work with autocalc fields. If there any autocalc attributes named in the getAttrs section of your sheet worker, those attributes will not be read. If that's not the case, we'll need to see more of the code to be able to figure out where things are going wrong.
GiGs said: As Rabulias says, sheet workers cant update disabled attributes. Also I notice something weird about your attribute names: <input type="number" name="attr_foo_vp_max" value="@{vp_max}" disabled="true" /> <input type="number" name="attr_foo_mp_max" value="@{mp_max}" disabled="true" /> <input type="number" name="attr_foo_vp_max_2" value="@{vp_max}" disabled="true" /> <input type="number" name="attr_foo_mp_max_2" value="@{mp_max}" disabled="true" /> the existence of foo_vp_max_2 makes me wonder if something is iffy here. In roll20 attributes that end in _max are special. But the fact you have ones ending in _max_2 has me scratching my head. But the first thing to check is: are any of the attributes used in this calculation autocalc fields? That is, ones that have a calculation that is not made by a sheet worker. Things like <input type="number" name="attr_something" value="@{some}+@{thing}" disabled="true" /> sheet workers do not work with autocalc fields. If there any autocalc attributes named in the getAttrs section of your sheet worker, those attributes will not be read. If that's not the case, we'll need to see more of the code to be able to figure out where things are going wrong. Adding "_2" to the max attribute names was literally the last thing I did before posting for help on the forum, in my own efforts to debug. It was to see if having two input elements with the same name was causing the bug. So it's not the source of the bug. I just went through and got rid of all my autocalc fields, except the "foo" autocalc inputs that are just for output and will never be used in calculations. Surprisingly, it did not fix the issue. (It did break two other character stats, but that should be easy to fix. Unless this same bug pops up there.) I'm struggling to know what code to paste here that would be helpful in a vacuum. Can you give me any direction about what part of the code you need to see? Or should I just upload the whole project to GitHub and give you a link to that? I doubt anyone wants to comb through my whole project ...
Here's the GitHub repo in case that is &nbsp;what you want. <a href="https://github.com/MEBonham/Roll20-CRE8-CharSheet" rel="nofollow">https://github.com/MEBonham/Roll20-CRE8-CharSheet</a>
I found the Best Practices/CSS Wizardry recommendation to use attr-tied &lt;span&gt;s instead of disabled inputs, and I'm working on refactoring that way. Apparently the problem was &nbsp;in the disabled inputs displaying what they were supposed to, not in the setAttrs() function, because the &lt;spans&gt; for these _max attributes seem to be behaving properly. Problem probably solved.
How do I add [SOLVED] to the title of this thread? I don't want to delete the thread in case someone in the future has a similar issue.
1587047804
GiGs
Pro
Sheet Author
API Scripter
I'm glad you got it sorted! Adding SOLVED to thread titles would be a good idea, but the forum doesnt support that. I think most things do get solved, so its probably not necessary.