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 .
×
May your rolls be merry + bright! 🎄
Create a free account

[nWoD] I made a new health tracker script...

1469051950

Edited 1469202598
L00kingGla55
Sheet Author
I wrote a script to make tracking health easier for my players (explaining nwod health is always confusing, even to nWoD veterans). <a href="https://jsfiddle.net/patrick_pineda/6yzaw2ex/" rel="nofollow">https://jsfiddle.net/patrick_pineda/6yzaw2ex/</a> I need to be up-front about this; I've never written anything in javascript prior to this. The code is probably ugly to those who actually have a better grip on programming. I'd like to modify the God Machine Chronicle sheet (yes, i know the official sheet is better... but my players have been using that one for a while.) I've been testing this in a new blank campaign on its own, but I can't get it to behave like it does in jsfiddle. I'm hoping someone can take a look and give me some tips on how to make it work within roll20?
1469074083
Lithl
Pro
Sheet Author
API Scripter
I notice in the comments of your script, you say "roll20 apparently can't get values based on ids?" Sheet Worker Scripts (the things that are part of character sheets, as opposed to API scripts) are sandboxed, so that they can't manipulate the DOM; if sheet workers had access to the document &nbsp;object, you could use a sheet worker to do literally anything you wanted to any part of the VTT, not just manipulate a character sheet. Sheet workers operate on an event system: opening the sheet for the first time in a session, changing an attribute, adding a repeating item, or deleting a repeating item are all events they can respond to. (I think &nbsp;they can respond to reordering repeating items as well, but I'm not 100% certain about that.) For example: on('change:myHealth0 change:myHealth1 change:myHealth2 ...', function() { // this function executes when any of the myHealthN attributes change }); Once the event fires, the sheet worker script generally needs to get the value of those attributes, and occasionally the values of other attributes as well. This is done with the getAttrs function: on('change:myHealth0 change:myHealth1 change:myHealth2 ...', function() { getAttrs(['myHealth0', 'myHealth1', 'myHealth2', ...], function(values) { // values.myHealth0 will be the value of the myHealth0 attribute, values.myHealth1 will be myHealth1, etc. }); }); Finally, the sheet worker generally needs to set the value of some attributes in order to do anything useful. This is done using the setAttrs function: on('change:myHealth0 change:myHealth1 change:myHealth2 ...', function() { getAttrs(['myHealth0', 'myHealth1', 'myHealth2', ...], function(values) { var newMyHealth = values; // do stuff. let's say we sort the myHealth values like a priority queue so aggravated values have highest priority // and get shifted over to the myHealth0, etc, while bashing and undamaged have the lowest priority and get shifted // over to the myHealth10, etc. setAttrs({ myHealth0: newMyHealth.myHealth0, myHealth1: newMyHealth.myHealth1, myHealth2: newMyHealth.myHealth2, ... }); }); }); Also, as a side note, JSFiddle has three separate panes for source code; the top-left is intended for HTML only, and the bottom-left is intended for JavaScript only. As you've demonstrated, you can certainly put a &lt;script&gt; block in the HTML pane, but separating the two makes fiddles easier to read. =)
1469121245

Edited 1469121271
L00kingGla55
Sheet Author
Thanks Brian! As mentioned previously, this is the first time I've ever taken a stab at coding anything; I'm learning as I go! Your explanation makes a lot of sense out of things on the wiki I couldn't fully get my head around. The idea behind this is to allow players to simply apply damage at the press of a button instead of having to enter numbers. It's not just a matter of simply ordering the damage by priority, unfortunately.&nbsp;The biggest reason for this is to correctly upgrade damage types when there are no empty health boxes left, which is a frequent source of confusion for nWoD newbs and pros alike (it would save us quite a bit of rules consulting to have it handled automatically.) Having to manually enter health values somewhat defeats the intended purpose for this, unfortunately.&nbsp; That said, Is there anything that can listen for a click event? Possibly a workaround using roll buttons? Or possibly a way to use css voodoo to make a text input field appear as a button? Once again, thanks for the detailed response, that helps out a great deal!
1469132033
Lithl
Pro
Sheet Author
API Scripter
patrick p said: That said, Is there anything that can listen for a click event? Possibly a workaround using roll buttons? Or possibly a way to use css voodoo to make a text input field appear as a button? Sheet worker scripts can't respond to click events. However, you could create something close to that, and you even approached the solution with your last idea. You could use CSS to make a checkbox look like &nbsp;a button, and you could have the sheet worker fire on the checkbox's value (checked vs. unchecked) changing. Check out the CSS Wizardry thread for tips on styling checkboxes.
Awesome! Thanks again Brian! I'll update this thread when I have a new version.