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

[Best Practices] Hidden Input vs. Written Value?

1630010861
John D.
Pro
Sheet Author
Sheet Authors and Coders, I'm looking for guidance/perspective on this subject of whether to embed placeholders in my HTML for values that players either will never see or interact with, or just write these values to the character sheet via sheet workers.  Here's what I've boiled this down to, sanity check please! If a player can see or interact with certain values, then those values must exist in the HTML; but if a value is only used or required by a sheet worker then it does not require a placeholder in the HTML. Examples of values which should be embedded in HTML: Use case: player can assign a numerical value to an attribute, such as the character's Strength.  Example: <div> <input type="number" class="attribute" name="attr_attribute_strength" value="0" /> </div> Use case: player can see character's health status in the character's health status field.  Example:  <div> <span class="status" name="attr_health_status"></span> <input type="hidden" name="attr_health_status" value="Healthy|Injured|Out of Coffee" /> </div> Note: hidden input value is dynamically set by sheet worker! Example of value which does not need to be embedded in HTML: Use case: sheet worker can track the rowID of a repeating section currently in use by the character.  Example:  on(`clicked:repeating_weapons:armweapon`,(eventInfo)=>{ const rowID = eventInfo.triggerName.slice(eventInfo.triggerName.length-20); let setObj = {}; setObj.armedweapon = rowID; setAttrs(setObj); } Since rowID has no intrinsic value to the player and is only used by sheet workers, it can be written to the character sheet but is not otherwise revealed to the player in HTML. So this is really my question: in the last example, is it fine to write values to a character sheet that players won't interact with?  Or would this be confusing for other sheet authors that pick up the character sheet after me?  Or is there something technical that I'm missing that may cause issues down the road?
1630012051
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Personally, I agree with you. There's no need to make a hidden attribute for every attribute that only a sheetworker needs. There are some caveats here though. intermediate calculations that aren't displayed, but are used should be in the html. These attributes may be used by players coding API scripts or custom macros in which case they are useful to have in the html/attributes of the character Some things that don't seem like they have a use to the user, like row id, actually can be very useful when using API scripts or making custom macros and can add some capability by being displayed on the sheet. That said though, things like the sheet_version attribute that I add to all my sheets doesn't need to be in the html because it's only purpose is to tell the sheetworker what update functions to run.
1630012635
GiGs
Pro
Sheet Author
API Scripter
John D. said: Or would this be confusing for other sheet authors that pick up the character sheet after me?  This would be my concern. There are lots of attributes that don't technically need attributes defined in the html, but it can make things clearer for later sheet maintainers and developers. In one of my sheets I have a "configuration" section of the HTML, which isn't visible to players but is to developers (which admittedly is only me), which includes all the non-repeating attributes of this sort, purely so it's easy to keep track of attributes of this sort. But if the sheet workers are reasonably well-documented, you wouldn't need anything like this - it's purely for personal taste.
1630033561
Finderski
Pro
Sheet Author
Compendium Curator
Scott C. said: That said though, things like the sheet_version attribute that I add to all my sheets doesn't need to be in the html because it's only purpose is to tell the sheetworker what update functions to run. And I display sheet number to help with troubleshooting, since some people may take the code and use it as a custom sheet. 
1630067292
Andreas J.
Forum Champion
Sheet Author
Translator
Finderski said: And I display sheet number to help with troubleshooting, since some people may take the code and use it as a custom sheet. Yeah I have the sheet version there so people will notice when the sheet is updated, and be on the lookout for changes. I've yet to try out integrating sheet update messages for people like how at least the GURPS sheet does.