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

Sheet Worker Beginner

1502984212
Lav
Sheet Author
I've been designing games for tabletop, and decided one of my games would be better to put on the virtual tabletop. So I've taught myself how to make a decent character sheet. Everything's been handleable with the whole process of learning HTML and CSS until I've tried to learn how to write Sheet Workers. Now I'm at a dead stop and don't know where to go. Here's where my understanding is at so far: I've read the Sheet Worker Scripts page from the Wiki, I have taken the Codecademy course for Javascript, I've learned that you can't access the Document object. It feels like I've learned how to read and comprehend a language, but I have no clue how to speak it. Where should I go? Where should I get started? Where's a good place to learn? Where's a good place to practice for someone looking to make Sheet Workers specifically? Is there a procedure I should know about for the general process of writing code for a project? I'll also take any "when I was in your shoes" rambling as well! :) Thank you very much.
1502986353
Jakob
Sheet Author
API Scripter
Usually, the best way to learn something is to do it! Start solving the problems you want to solve using sheet workers, and learn along the way :). Now, that probably wasn't very helpful. I could also encourage you to look at code others have written, which you should do; just realize that many sheet authors are also amateurs (such as me), hence the code may not be the most elegantly-written example. That probably also wasn't helpful. Let me try something else: depending on what your course taught you, much of it (everything dealing with manipulation of the DOM) is not going to be very helpful. Here's some important things you need to keep in mind that might make sheet workers different from what you've learned: Sheet workers are event-driven.  Everything interesting your workers do will happen in response to a certain event on the sheet; most of the time, the triggering event will be changing an attribute on the sheet (i.e., the value of some input, be it a checkbox, radio, text, number input, or textarea). This is what the on("change:attr", function () { ...}) is there for: it's about registering a function that's supposed to be executed every time attr changes. Sheet workers can only really do one thing.  Sheet workers can change the value of attributes, and that's pretty much it (they can also remove repeating rows, but that's not their main use). If you want your sheet workers to do a thing, ask yourself if it can be accomplished by changing the value of an attribute (this includes being able to (un)check checkboxes), +perhaps some CSS. If yes, you can do it with sheet workers. If not, you cannot. Sheet workers are asynchronous.  The main interesting functions you have access to in sheet workers, namely getAttrs, setAttrs, and getSectionIDs, take as their second argument functions that do other stuff. This means that you cannot trust that your code will simply be executed from top to bottom, and have to write in such a way that it makes sense no matter when asynchronous functions are executed. This is often a source of confusion for people.
1502987833
Lav
Sheet Author
Ha! Hi, Jakob! I was secretly hoping you'd reply. Going through the code on the Blades Sheet Workers and looking up what each thing was doing taught me a lot. Those sheets have just shaped up so well. That was all very helpful. Don't sell yourself short! :D