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 - Stat tables for new Unity RPG sheet

1581706629

Edited 1581707329
Hi folks, I'm trying to build a halfway decent sheet for Unity RPG by Modiphius as my first custom, and, predictably, I'm having beginner's issues.  I copied a pre-existing formula for importing race-linked attribute values from a table in a sheet worker, which seemed pretty simple, but it seems to be doing nothing.  To keep it simple I stripped out the HTML I've got so far so I could reproduce just the relevant stuff.  So:      <select name="attr_race">                         <option value="none" selected>Race?</option>                     <option value="afflicted">Afflicted</option>     <option value="furian">Furian</option>     <option value="human">Human</option>     <option value="vallan">Vallan</option>                     </select>                    <label>MIGHT</label>  <input type="number" class="sheet-open" name="attr_might"/>                     <br/>                     <label>AGILITY</label> <input type="number" class="sheet-open" name="attr_agility"/>                      <br/>                     <label>MIND</label>  <input type="number" class="sheet-open" name="attr_mind"/>                      <br/>                      <label>PRESENCE</label>  <input type="number" class="sheet-open" name="attr_presence"/>                       <br/>  <script type="text/worker">          on("change:race sheet:opened", function () {     getAttrs(['race'], function(values) {         const races = {          none: {might: 0, agility: 0, mind: 0, presence: 0},          human: {might: 1, agility: 1, mind: 1, presence: 1},          vallan: {might: 0, agility: 2, mind: 1, presence: 1},          furian: {might: 2, agility: 1, mind: 0, presence: 1},          afflicted: {might: 1, agility: 1, mind: 2, presence: 0}         };         let race = values.race;                 if (!races.hasOwnProperty( race )) {            console.log("Error: The item " + race + " is not found within the race Object.");            return;         }          setAttrs({             "might": races[race].might,             "mind": races[race].mind,             "agility": races[race].agility,             "presence": races[race].presence         });     }); }); </script> In case it's not obvious, it's just supposed to populate the core attribute fields with those bases when you pick a race, but right now nothing happens.  I'm sure it's a rookie mistake, but I'm pretty sure my code is just like the one linked above, so I'm at a loss.  Would love some feedback, thanks!
1581741531

Edited 1581756257
GiGs
Pro
Sheet Author
API Scripter
Your sheet worker code is fine, it should work (though the setAttrs statement could be shorter, see below). I'm not seeing an issue with your html either. If you create a new campaign and copy just the code above into it, does it work? I think the problem must be somewhere else, though it's hard to guess what it might be. Do you have any other sheet workers? If there's a syntax error in one of them it could stop this one working. Do you have multiple script blocks? if so, combine them all into one. Regarding simplifying the setAttrs function (I'm not sure why i did it the way i did in the linked post): notice that each of the race entries are things like {might: 1, agility: 1, mind: 1, presence: 1} Now, notice if you put this around it setAttrs( ); you'd have a valid setAttrs statement: setAttrs({might: 1, agility: 1, mind: 1, presence: 1}); normally written like so, but it it is identical: setAttrs({      might: 1,     agility: 1,     mind: 1,     presence: 1 }); With this in mind you can do this:         const scores = races[race];          setAttrs(scores); or even just         setAttrs(races[race]); but i prefer the first version in case you need to do error checkjing-  having a named variable lets you output it to log and examine it. Here's what your worker would look like  on("change:race sheet:opened", function () {     getAttrs(['race'], function(values) {         const races = {             none: {might: 0, agility: 0, mind: 0, presence: 0},             human: {might: 1, agility: 1, mind: 1, presence: 1},             vallan: {might: 0, agility: 2, mind: 1, presence: 1},             furian: {might: 2, agility: 1, mind: 0, presence: 1},             afflicted: {might: 1, agility: 1, mind: 2, presence: 0}         };         const race = values.race;                 if (!races.hasOwnProperty( race )) {            console.log("Error: The item " + race + " is not found within the races Object.");            return;         }         const scores = races[race];          setAttrs(scores);     }); }); Note that you dont actually need to error section, since your select value can only be the listed values - that error can never fire. It's only there in case you start expanding the race select, to catch typos and the like.
Oh.... Oh dang, it just doesn't do its thing in the preview window.  It works in-game.  Originally it did nothing in-game, then I made some critical changes but only tested in the preview window.  Well, I feel dumb.   Thanks for your help in streamlining the code!
1581785354
GiGs
Pro
Sheet Author
API Scripter
the sheet preview doesnt really work with sheet workers, and has other failings too. It's always best to check in-game. You should try the new custom sandbox feature, it makes editing much easier - especially for sheet workers. You have to use an external html and css file, but reloading them in game is a snap, so you can make tweaks to your html or css, and reload that file in a second (while having a character open) and see changes instantly. Much better than refreshing the browser page and waiting several seconds for it to load, then re-open a character.
1581787509
Andreas J.
Forum Champion
Sheet Author
Translator
You should also take a new read of the Building Character Sheets , as this Preview Panel thing is mentioned there, so there could be other useful things you might find with the recently updated article. It should be better structured, and contain new info on various things relating to character sheet creation.