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

Custom sheet: many checkboxes; simple event?

1680059050
Nash
Pro
Sheet Author
Compendium Curator
I’m building a custom sheet for Rolemaster Unified (RMU).  For skill purchasing I need either a drop down or a pair of checkboxes for each skill.  There are slightly over 100 skills in RMU.  I’m using a sheet worker for the bulk of the calculations. So I have two related questions; can I attach a sheet worker event to items by class? on(‘changed:class_button’,…) or similar. If not will it be a problem if I attach a handler to each?    Otherwise should I use auto calculations to build this part?
1680121879

Edited 1680121895
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You technically can attach a handler via class using the Roll20 limited jquery implementation. However, you do NOT  want to use this method. The listener attached by the jquery implementation does not respond to changes in the database; it only responds to user interaction. The better method is to attach a listener to each checkbox that runs the same function. As for autocalc, it should hardly ever be used in a modern sheet. It is still around purely as a legacy feature to support older sheets. Additionally, if you have more than 100 skills and 2 checkboxes for each, this use of autocalcs alone would cause your sheet to lag to a stand still on sheet open. Considering the amount of repetitive code it sounds like you are going to be making, might I recommend looking at using PUG to write your html. Additionally, the K-scaffold would make hooking up each of these checkboxes to their respective function much simpler.
1680122278
Nash
Pro
Sheet Author
Compendium Curator
Thanks for the replay Scott! That's the answer I feared. As for repetitive code... I have that problem sorted.  I am using a template library to generate all the code for me. So my next question: is it better to 100 on("changed:button_<XYZ>"...) or one big on("changed:button1 changed:button2 ..."...)  or some combination of both (ie 10 on() calls, each with items).  Generating the code for each for me will essentially be the same.  [ie, once for each skill, once total, once for each category (each containing between 3-10 skills)]
1680207111
GiGs
Pro
Sheet Author
API Scripter
If multiple copies of the buttons will ever be triggered at the same time (and that includes cascading events: on sheet worker causes changes, which then trigger another, and so on), it's better to use one big sheet worker. If none of the sheet workers trigger other sheet workers, then it is just as efficient to use lots of separate sheet workers (and they are usually easier to write).