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 for Starting HP in Unity - class-specific modifiers.

Hello all, thanks for reading. Unity by Modiphius grants every character class a "Main attribute" out of the core 4 that applies to their attack rolls.  So while everyone has Might, Mind, Agility, and Presence, a Judge will swing with Might, a Mystic will swing with Mind, and a Phantom will swing with Agility.  The Main attribute applies similarly to HP.  Tanky classes like Dreadnoughts will get a base 14 starting HP + their Might value, while relative wimps like Phantoms get 10 base + Agility - again, Main Attribute is the modifier. So I'm trying to create a sheet worker that correctly pulls the right Main Attribute when you select Class at the beginning, then auto-applies it to all its relevant spots.  I'm getting tripped up as to how I feed it through correctly...   on("change:class sheet:opened", function () {     getAttrs(['class'], function(values) {         const classes = {          none: {main: "Main Attribute"},          dreadnought: {main: "Might"},          driftwalker: {main: "Mind"},          fellhunter: {main: "Agility"},          judge: {main: "Might"},          mystic: {main: "Mind"},          phantom: {main: "Agility"},          priest: {main: "Mind"},          primalist: {main: "Mind"},          sentinel: {main: "Might"}         };         const classy = values.class;              if (!classes.hasOwnProperty( classy )) {            console.log("Error: The item " + classy + " is not found within the classes Object.");            return;         }          const metrics = classes[classy]         setAttrs(metrics);     }); }); That's the wimpy start I have.  Not sure where to go from there. I'm envisioning that the arrays would eventually have Attack Rating (attr_ar) and HP (attr_hp).  Could anyone sort of outline the direction I should take to make these not-so-convoluted?
1581971942
GiGs
Pro
Sheet Author
API Scripter
So, if notice that each class is inside a { } group, and you access it with classes[name]. Now notice that inside each element in the {} group, the items are also inside a {} group. So you can access them with [name] also. So its as simple as classes[classy]['main'] For hardcoded names like 'main', not set by variables, you can use the .name syntax, which is often easy to read because you dotn need to remember the quotes. So that would be classes[classy].main Since you are planning to have a bunch of attributes inside the classes, you have established a metrics group which is good. You can grab its parts with just [] or . So         const metrics = classes[classy];         const main = metrics.main;         setAttrs(metrics); Remembering that metrics is classes[classy] , what we have here is just another way to write  classes[classy].main , but as noted, is handy if you are going to access multiple properties. Hope this helps! classes[classy] will give you something like