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

Several Questions - Character Sheet Design

1473689183
Falcon
Pro
Sheet Author
1) Is there anyway to either write in CSS or in sheetworkers to show numbers in a comma format 123,123,123? 2) Are there videos on how to use Sheet Workers?  I am have spent hours and still not getting it - the wiki hasn't helped. 3) Can you use sheet workers to show specific data.  For example in 2E D&D ability scores output is really on a table?
1473746448
Lithl
Pro
Sheet Author
API Scripter
A sheetworker could update a text field to insert digit grouping separators where appropriate. However, the user would then have to work around the extra characters the next time they edited the value. Alternatively, you could have the user enter a number, and then use a sheet worker to update a non-editable "display" version of the associated attribute with separators. Something to consider: in different languages, digit grouping is handled differently. European languages separate numbers by thousands. East Asian languages separate by ten-thousands (at least verbally, they often separate by thousands in text). India is particularly weird in that the first three digits left of the decimal separator are together, and everything further is in groups of 2, so 1.5 million is 15,00,000. Also worth noting, different countries have different conventions for what to use as the separator. Some would write 100,000.45. Others 100.000,45. The current ISO standard and recommendation in multiple manuals of style is a thin space ( ) where available, or a normal word space (or no digit grouping) where a thin space is not available.
1473746814
Falcon
Pro
Sheet Author
Thanks Brian.  I am more concerned with US standard.  Specifically for my campaign.  I am going to run a 2nd edition game and struggle with the millions of xp one may have and being able to read it.  I am thinking of using decimal points to make it easier (divide everything by 10000 or something). Your non-editable field idea is perfect though.  I could then just add a number which would then get added to a total. So is there a video on how to make your ow sheetworkers.  Struggling with understanding it.  Got the concepts down but execution is much more difficult.
1473759372
Lithl
Pro
Sheet Author
API Scripter
What exactly are you struggling with? Here's an example that may be relevant to what you're looking to accomplish: on('change:gained_xp', function() { // when @{gained_xp} changes, do this getAttrs(['gained_xp', 'total_xp_display'], function(values) { // get @{gained_xp} and @{total_xp_display}, and store // their current values as the `values` object var total_xp = parseInt(values.total_xp_display.split(',').join('')); // get @{total_xp_display} as a number total_xp += parseInt(values.gained_xp); // add @{gained_xp} to `total_xp` if (total_xp.toString().length >= 5) { // don't add digit groupings for a 4-digit number total_xp = total_xp.toString().replace(/(\d)(?=(\d{3})+$/g, '$1,'); // add comma separator using regex } setAttrs({ total_xp_display: total_xp, // update @{total_xp_display} with new total gained_xp: '' // clear @{gained_xp} }); }); }); You could then have HTML something like this: Total XP: <span name="attr_total_xp_display"></span> <br> <label>Gained XP: <input type="number" name="attr_gained_xp"></label> When you enter a number in the input and then change focus to something else (by hitting [tab] or clicking somewhere else on the sheet), the input would get cleared and the number would be added to the total XP, which is being rendered as text instead of an input you can edit.
1473783403
Falcon
Pro
Sheet Author
Man - that seemed easy.  ROFL - thanks for showing me both sides.  So do you need all that extra sheetworker stuff that The Aaron did before doing sheet workers?
1473825527
Lithl
Pro
Sheet Author
API Scripter
TAS only adds convenience methods to sheet workers. Useful for some of the more complicated things, but certainly not necessary.
1473827586
Falcon
Pro
Sheet Author
I couldn't get this to work.  It showed up as NaN and it didn't clear the number.                     Total XP: <input name="attr_total_xp_display" readonly="readonly"><br>                     <div class="sheet-col-1-3"><input class="sheet-center" type="number" name="attr_gained_xp">Gained XP</div> Then my other portion: <!-- SHEETWORKERS --> <script type="text/worker"> on('change:gained_xp', function() { // when @{gained_xp} changes, do this     getAttrs(['gained_xp', 'total_xp_display'], function(values) { // get @{gained_xp} and @{total_xp_display}, and store                                                                    // their current values as the `values` object         var total_xp = parseInt(values.total_xp_display.split(',').join('')); // get @{total_xp_display} as a number         total_xp += parseInt(values.gained_xp); // add @{gained_xp} to `total_xp`         if (total_xp.toString().length >= 5) { // don't add digit groupings for a 4-digit number             total_xp = total_xp.toString().replace(/(\d)(?=(\d{3})+$/g, '$1,'); // add comma separator using regex         }       setAttrs({             total_xp_display: total_xp, // update @{total_xp_display} with new total             gained_xp: '' // clear @{gained_xp}         });     }); }); </script>
1473838273
Lithl
Pro
Sheet Author
API Scripter
Try this one. I actually tested it this time, instead of writing it on the spot and assuming it'd work ~_^ on('change:gained_xp', function() {     getAttrs(['gained_xp', 'total_xp_display'], function(values) {         var total_xp = parseInt((values.total_xp_display || '').toString().split(',').join('')) || 0;         total_xp += parseInt(values.gained_xp) || 0;         if (total_xp.toString().length >= 5) {             total_xp = total_xp.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');         }         setAttrs({             total_xp_display: total_xp,             gained_xp: ''         });     }); }); There were a couple of errors in the original, such as handling @{total_xp_display} not having any value at all to start with, and the regex I wrote was malformed (missing a closing parentheses), and it didn't work correctly even with the paren added back in.
1473860030
Falcon
Pro
Sheet Author
That worked.  Thank you!!