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 Not Working?

1491201970

Edited 1491202092
Azurift
Sheet Author
I've been wracking my brain for several hours over this, and it still doesn't work. All I want to get working is a simple status system where, depending on your HP, updates the status to "DEAD" if you're below 0 HP, or "ALIVE" if it is above. Here is the code: <input type="text" name="attr_status"> <input type="number" name="attr_HP" value="0"> <script type="sheet/worker"> on("change:HP", function() { getAttrs(["HP"], function(values) { var output = ""; if (values.HP < 0) { output = "DEAD"; } else { output = "ALIVE"; } setAttrs({ status: output }); }); }); </script> What am I doing wrong?
1491207414

Edited 1491207485
Natha
KS Backer
Sheet Author
API Scripter
Perhaps that "values.HP" is not recognized as an integer. Try using a local variable to verify this? Something like : on("change:HP", function() { getAttrs(["HP"], function(values) { var output = ""; var hp = parseInt(values.HP) || 0; if (hp < 0) { output = "DEAD"; } else { output = "ALIVE"; } setAttrs({ status: output }); }); });
1491207524

Edited 1491207612
Finderski
Plus
Sheet Author
Compendium Curator
This is from the  wiki : Note : The entire string will have been translated into lowercase and thus might not be suitable for being fed directly into getAttrs(). and then later again: Note: All attribute names are lowercased in events. So even if you normally refer to an attribute as "Strength", use "change:strength" in the event listener. So, I'd recommend changing your 'on' statement to be: on("change:hp", function() { Not sure that's the issue, but that's what I can recommend... Edit: What Natha said, too...
Thanks for the help, guys, but I tried both approaches and it still doesn't seem to even run for me. I've scoured all over the internet and found similar answers to similar problems, yet those approaches don't seem to work at all either. Even when I copy + paste their entire code, it doesn't seem to even run. Am I missing something, here?! I feel like I'm going crazy, lol.
1491219862
Natha
KS Backer
Sheet Author
API Scripter
Perhaps your character have several attributes named "HP" (hp or HP) ?
1491235945

Edited 1491236002
Azurift
Sheet Author
The code I posted is all of it -- I even removed all of my previous work and loaded just the code from above (no CSS, either) and it still doesn't work. I'm having flashbacks of CSI 102 from when I was in college, lol. Here's the updated code for posterity's sake: <div class="charsheet">     <input type="text" class="sheet-status-name" name="attr_status">     <input type="number" class="sheet-hp" name="attr_hp" value="0">          <script type="sheet/worker">     on("change:hp", function() {        getAttrs(["hp"], function(values) {           var output = "";           var temphp = parseInt(values.hp) || 0;           if (temphp < 0) {              output = "DEAD";           }           else  {              output = "ALIVE";           }           setAttrs({              status: output           });        });     });         </script> </div>
1491236415

Edited 1491236479
Natha
KS Backer
Sheet Author
API Scripter
Could you add a "console.log('temphp : ' + temphp);" line and check the browser console log? And/or try using another numeric attribute than "hp", just for the sake of it ?
Done, but to no avail: &lt;div class="charsheet"&gt; &nbsp; &nbsp; &lt;input type="text" class="sheet-status-name" name="attr_status"&gt; &nbsp; &nbsp; &lt;input type="number" class="sheet-hitpoints" name="attr_hitpoints" value="0"&gt; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &lt;script type="sheet/worker"&gt; &nbsp; &nbsp; on("change:hitpoints", function() { &nbsp; &nbsp; &nbsp; &nbsp;getAttrs(["hitpoints"], function(values) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var output = ""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var temphp = parseInt(values.hitpoints) || 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('temphp : ' + temphp); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (temphp &lt; 0) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output = "DEAD"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;output = "ALIVE"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status: output &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp;}); &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &lt;/script&gt; &lt;/div&gt; I couldn't find the console log entry for the temphp var, but here's the log anyways: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' https://*.googlesyndication.com https://*.doubleclick.net <a href="https://partner.googleadservices.com" rel="nofollow">https://partner.googleadservices.com</a> <a href="https://www.googletagservices.com" rel="nofollow">https://www.googletagservices.com</a> <a href="https://ssl.google-analytics.com" rel="nofollow">https://ssl.google-analytics.com</a> <a href="https://www.google-analytics.com" rel="nofollow">https://www.google-analytics.com</a> <a href="https://ajax.googleapis.com" rel="nofollow">https://ajax.googleapis.com</a> <a href="http://ajax.googleapis.com" rel="nofollow">http://ajax.googleapis.com</a> <a href="https://d3clqjduf2gvxg.cloudfront.net" rel="nofollow">https://d3clqjduf2gvxg.cloudfront.net</a> <a href="https://cdn.firebase.com" rel="nofollow">https://cdn.firebase.com</a> https://*.firebaseio.com https://*.tokbox.com https://*.opentok.com <a href="http://static.opentok.com" rel="nofollow">http://static.opentok.com</a> <a href="http://www.google-analytics.com" rel="nofollow">http://www.google-analytics.com</a> <a href="http://cdn.crowdin.com" rel="nofollow">http://cdn.crowdin.com</a> <a href="https://crowdin.com" rel="nofollow">https://crowdin.com</a> <a href="http://stun.l.google.com" rel="nofollow">http://stun.l.google.com</a>". Either the 'unsafe-inline' keyword, a hash ('sha256-nf5TAjcNzIYoTeqbYyT+OultDPzQ4idh5rgHHaJiA9s='), or a nonce ('nonce-...') is required to enable inline execution. app.roll20.net/:13 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' https://*.googlesyndication.com https://*.doubleclick.net <a href="https://partner.googleadservices.com" rel="nofollow">https://partner.googleadservices.com</a> <a href="https://www.googletagservices.com" rel="nofollow">https://www.googletagservices.com</a> <a href="https://ssl.google-analytics.com" rel="nofollow">https://ssl.google-analytics.com</a> <a href="https://www.google-analytics.com" rel="nofollow">https://www.google-analytics.com</a> <a href="https://ajax.googleapis.com" rel="nofollow">https://ajax.googleapis.com</a> <a href="http://ajax.googleapis.com" rel="nofollow">http://ajax.googleapis.com</a> <a href="https://d3clqjduf2gvxg.cloudfront.net" rel="nofollow">https://d3clqjduf2gvxg.cloudfront.net</a> <a href="https://cdn.firebase.com" rel="nofollow">https://cdn.firebase.com</a> https://*.firebaseio.com https://*.tokbox.com https://*.opentok.com <a href="http://static.opentok.com" rel="nofollow">http://static.opentok.com</a> <a href="http://www.google-analytics.com" rel="nofollow">http://www.google-analytics.com</a> <a href="http://cdn.crowdin.com" rel="nofollow">http://cdn.crowdin.com</a> <a href="https://crowdin.com" rel="nofollow">https://crowdin.com</a> <a href="http://stun.l.google.com" rel="nofollow">http://stun.l.google.com</a>". Either the 'unsafe-inline' keyword, a hash ('sha256-gCgVkAhT4jg1bWpbaHmyMrHQxNIEPZFk50qjzDbMloA='), or a nonce ('nonce-...') is required to enable inline execution. app.js:31 70 app.js:31 TOUCH SUPPORTED: false app.js:31 USING WEBGL ACCELERATION... app.js:31 WEBGL STARTUP SUCCESS app.js:33 Custom Sheet Translation app.js:26 select app.js:26 Switch mode to select app.js:42 Initializing new dice engine with randomness... app.js:42 Using random entropy app.js:46 Compiling sheet... app.js:46 Finding sheet rolls... app.js:47 window resize app.js:32 Final set zoom! app.js:31 UPDATE GL SIZE! app.js:32 Final set zoom! tutorial_tips.js:7 tuts loaded app.js:38 Final page load. app.js:48 Refresh jukebox List! app.js:37 Auth'ed. app.js:37 Go post auth! app.js:37 initial setup app.js:35 T.r_callbacks: Object_changing: false_escapedAttributes: Object_pending: Object_previousAttributes: Object_silent: ObjectactivePage: ()activePageIndex: 0attributes: Objectbootstrapped: truecardtrades: T.rchanged: Objectcharacters: T.rcid: "c0"currentOrderArray: Array[0]currentPlaylistPlayingID: ()custFx: T.rdecks: T.rfbauthinfo: ObjectgameFullyLoaded: truegetPageIndex: ()handlePlayerPageChanges: (t)handouts: T.rhands: T.rinitActivePage: ()initiativewindow: T.rpages: T.rparentRef: Xplayers: T.rrollabletables: T.rshowSettings: ()switchPageById: ()switchPageByIndex: ()tokendisplay: Objectview: T.r__proto__: t.Model app.js:37 Got players value... app.js:37 joining game... 2app.js:35 Full load page! app.js:37 We have 2 pages app.js:35 Player -KaOTj5Zwix1SpMnrEup is offline... app.js:14 THREE.WebGLRenderer 69 app.js:36 Global Volume: 100=1 app.js:37 Deferred finish joining... app.js:31 Firebase Online app.js:44 Loading Roll20 Chat Event Handlers app.js:37 handle page changes app.js:37 false app.js:40 refershing page listings! app.js:33 Do refresh link cache! app.js:45 Refresh Journal List! app.js:45 Search took 7ms app.js:37 init active page! app.js:35 activate page! app.js:35 FULLY ACTIVATE VIEWS FOR PAGE. app.js:35 Graphics: 0 app.js:35 Paths: 0 app.js:35 Reorder by ZORDER app.js:38 Scan for new plays! app.js:40 refershing page listings! app.js:48 Refresh jukebox List! 7app.js:44 Didn't find a roll template called 'pf_check' d20.textchat.incoming @ app.js:44 2app.js:44 Didn't find a roll template called 'PFAttack' d20.textchat.incoming @ app.js:44 8app.js:44 Didn't find a roll template called 'pf_check' d20.textchat.incoming @ app.js:44 app.js:39 Show Character View Dialog! app.js:38 --- RENDER CHARACTIVE VIEW ---- app.js:38 Redoing charsheet html app.js:38 7ms to end of html app.js:33 239 app.js:38 Really updating character sheet values app.js:38 Setting up repeating sections took until 0ms app.js:38 Updating ALL VALUES app.js:38 Finding list of dirty attributes took until 0ms app.js:38 Querytest took until 0ms app.js:38 Attribute cache compliation took until 0ms app.js:38 Set values (including auto-calcuating variables) took until 1ms app.js:38 Appending to screen took until 1ms app.js:38 Took 1ms app.js:38 Really updating character sheet values app.js:38 Setting up repeating sections took until 0ms app.js:38 Finding list of dirty attributes took until 0ms app.js:38 Querytest took until 0ms app.js:38 Attribute cache compliation took until 0ms app.js:38 Set values (including auto-calcuating variables) took until 1ms app.js:38 Took 1ms app.js:39 blankVal, don't save app.js:47 window resize app.js:32 Final set zoom! app.js:31 UPDATE GL SIZE! app.js:32 Final set zoom!
1491244281
Finderski
Plus
Sheet Author
Compendium Curator
Just noticed the script tags are inside the character sheet. &nbsp;For me, I always have the script tags outside of the character sheet div. &nbsp;Try moving it above the character sheet. &nbsp;Something like: &lt;script type="sheet/worker"&gt; /* script stuff goes here */ &lt;/script&gt; &lt;div class="charsheet"&gt; &lt;!--char sheet stuff goes here --&gt; &lt;/div&gt;
1491245650

Edited 1491245681
Lithl
Pro
Sheet Author
API Scripter
Finderski said: Just noticed the script tags are inside the character sheet. &nbsp;For me, I always have the script tags outside of the character sheet div. &nbsp;Try moving it above the character sheet. &nbsp;Something like: &lt;script type="sheet/worker"&gt; /* script stuff goes here */ &lt;/script&gt; &lt;div class="charsheet"&gt; &lt;!--char sheet stuff goes here --&gt; &lt;/div&gt; Actually, I would remove the .charsheet div entirely. All of your character sheet code is automatically wrapped in a .charsheet div, and adding another one is just going to make the CSS more confusing. That's not going to solve the sheet worker script problems, though.
1491266927

Edited 1491266950
Azurift
Sheet Author
I removed the charsheet div and even tried it on Firefox to no avail (I normally use Chrome.) Does this code happen to work for you guys? I'm starting to think it might be an issue on my end, somehow.
1491292693
Natha
KS Backer
Sheet Author
API Scripter
Can you share the whole html / css sources from your sheet? I could try then.
1491293401
Jakob
Sheet Author
API Scripter
Very stupid comment: you are supposed to use &lt;script type="text/worker"&gt;, not sheet/worker. Right?
1491294455
Finderski
Plus
Sheet Author
Compendium Curator
Jakob said: Very stupid comment: you are supposed to use &lt;script type="text/worker"&gt;, not sheet/worker. Right? D'oh!! Not stupid at all...and you are correct. :)
Yep, looks like the &lt;script type="text/worker"&gt; thing worked! Thanks, guys!
1491340530
Natha
KS Backer
Sheet Author
API Scripter
* face palm *