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

An Attribute set to 0 no longer shows on the sheet

1467203921
Kryx
Pro
Sheet Author
API Scripter
I think this may be a regression as it previously worked. The sheetworkers have set the initiative: It's set to "0", but that value no longer shows via: <span name="attr_initiative" class="presentation big-text bold block center initiative-total"></span> It's just empty: <span name="attr_initiative" class="sheet-presentation sheet-big-text sheet-bold sheet-block sheet-center sheet-initiative-total"></span> Thanks for looking into this.
1467230488
Lithl
Pro
Sheet Author
API Scripter
Have you tried putting a 0 in the source HTML (essentially creating a default value)?
1467238577
Kryx
Pro
Sheet Author
API Scripter
I'm sure that would solve what I'm trying to fix, but that shouldn't really be necessary. Spans should be able to show "0".
1467550159
Kryx
Pro
Sheet Author
API Scripter
I'm sure some bugs were lost in the recent release, but could this be addressed please?
1467709701
Kryx
Pro
Sheet Author
API Scripter
This issue occurs anytime the value is set to 0. It occurs for example if a character has 1 in a field and then reduces that field to 0. It still shows 1. See&nbsp;<a href="https://app.roll20.net/forum/permalink/3620902/" rel="nofollow">https://app.roll20.net/forum/permalink/3620902/</a>
1467759109

Edited 1467759132
Phil B.
Forum Champion
Sheet Author
Sorry about that, I remember seeing this and had the tab pinned and was going to get back to it but I think browser crashed or something and I lost it. Anyways,&nbsp;I just tested it out and it's working fine for me. Here's what I used to test, let me know if I'm missing something: &lt;input name="attr_test1" type="number" value="42" &nbsp;&gt; &lt;span name="attr_test1"&gt;&lt;/span&gt; The initial value is loaded as 42. I change the value to 0 and 0 shows up in the span. I change the value to 1 and 1 shows in the span, change is back to 0, using the arrows, and 0 shows up in the span.&nbsp; If you can give me some code with a simple test case that shows this happening I'll be happy to take a closer look at it.
1467798576

Edited 1467798695
Kryx
Pro
Sheet Author
API Scripter
I believe the issue relates to sheetworkers setting the value to 0. With an input I'm sure it works, but with sheetworkers setting the value to 0 it doesn't seem to work. I can make a simple test case later tonight if I have time.
1467812010
Kryx
Pro
Sheet Author
API Scripter
Yup, that's exactly it. Here is a test case for you: &lt;div&gt; &nbsp; &nbsp; &lt;span&gt;Test: &lt;/span&gt; &nbsp; &nbsp; &lt;input name="attr_test" type="number"&gt; &lt;/div&gt; &lt;div&gt; &nbsp; &nbsp; &lt;span&gt;Test1: &lt;/span&gt; &nbsp; &nbsp; &lt;span name="attr_test1"&gt;&lt;/span&gt; &lt;/div&gt; &lt;script type="text/worker"&gt; on("change:test", function() { &nbsp; &nbsp;getAttrs(["test"], function(values) { &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; test1: Math.floor((values.test-10) / 2) &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp;}); }); &lt;/script&gt; Change test to 12 and then to 10. You'll see test1 doesn't get updated from 1
1467995918
Phil B.
Forum Champion
Sheet Author
Thank you for this test case, I was able to recreate the issue and will be looking into it further today.
1467995949
Kryx
Pro
Sheet Author
API Scripter
Thanks Phil!
1468006371
Phil B.
Forum Champion
Sheet Author
I figured it out, it's happening because JS is kinda dumb. The technical explanation, if you're interested: We are setting the span's value with (newValue || defaultValue). Html inputs always pass their contents as a string, so if you set it to 0 then '0' is what's saved and ('0' || defaultValue) === '0'. This is why it works just fine sans sheetworker. When you set the value via sheetworker though, this doesn't necessarily happen. When you set the value to 0, 0 is what gets saved, and (0 || defualtValue) === defaultValue, which is undefined in this case, because JS is kinda dumb. Anyways, I'm committing the fix for this now, but it's too late on Friday and this isn't a game breaker so the fix won't actually make it live until Mondayish.&nbsp;