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

Requesting help with Sheetworker...

1547896654

Edited 1547896740
Ray
Pro
I am totally new to Sheetworker...could someone please tell me what is wrong with this script? <!-- CALCULATE STR WHEN STRXP IS MODIFIED - FORMULA : STRbase + STRXP = STR  /--> <script type="text/worker">     on("change:strxp", function()         {getAttrs(["STRbase", "STRXP"], function(values)             {var statTotal = parseInt(values["STRbase"])||0;                 statTotal += parseInt(values["STRXP"])||0;                          var strbase = Math.round(statTotal)||0;             setAttrs({"STR": str});             });         }); </script> for example...STRbase 10 + STRXP 2 should create attr STR 12... problem result...STR is not being created...i.e. it is not appearing in the "Attributes and Abilities" page, also no STR valuue is appearing on the character sheet. Thanks in advance...Ray
1547903182
Caden
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Do you have an <input> for the STR attribute? It can be visible as part of the sheet or type=hidden.  on("change:STRXP", function() {     getAttrs(["STRbase, "STRXP"], function(v) {         const base = parseInt(v.STRbase) || 0, xp = parseInt(v.STRXP) || 0, tot = base + xp;         const str = Math.round(tot) || 0;         setAttrs ({             STR : str         });     }); });
1547910948
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'd recommend doing a console.log(values) to make sure you're getting returned what you think you are. Additionally, log the calculated values of statTotal and strbase.
Cassie said: Do you have an <input> for the STR attribute? It can be visible as part of the sheet or type=hidden.  on("change:STRXP", function() {     getAttrs(["STRbase, "STRXP"], function(v) {         const base = parseInt(v.STRbase) || 0, xp = parseInt(v.STRXP) || 0, tot = base + xp;         const str = Math.round(tot) || 0;         setAttrs ({             STR : str         });     }); }); Hi Cassie. No...the STR attribute is being calculated from the STRbase and the STRXP attributes as follows: <input class="input45 center" type="number" disabled="true" name="attr_STRbase" value="10"> <input class="input30 center" type="number" name="attr_STRXP" value="0"> So, the purpose of the Sheetworker script is to determine the value of the STR attribute and output it to the "Attributes and Abilities" page. the formula will always be :  10 (STRbase) + ? (STRXP) =  ? (STR)
1547944080

Edited 1547944103
Ray
Pro
Scott C. said: I'd recommend doing a console.log(values) to make sure you're getting returned what you think you are. Additionally, log the calculated values of statTotal and strbase. Ok Scott....I understand what you are suggesting conceptually, but I have no idea of the syntax or how to implement the console.log  :/ I am currently reading the Sheetworker wiki to try and figure all this out  ;)
1547946574

Edited 1547946674
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
In your current code, it would be this: <script type="text/worker">     on("change:strxp", function(){         getAttrs(["STRbase", "STRXP"], function(values){             console.log(values)             var statTotal = parseInt(values["STRbase"])||0;                 statTotal += parseInt(values["STRXP"])||0;             console.log(`statTotal: ${statTotal}`);             var strbase = Math.round(statTotal)||0;             console.log(`strbase: ${strbase}`);             setAttrs({"STR": str});             });         }); </script> You would then see the log in the developer console (cmd+alt+i on mac chrome, ctrl+shift+i on pc chrome). I also noticed something, are you making multiple <script>'s for each sheetworker, or doing them all in one? You should only have a single <script> in your sheet.
1547950404
GiGs
Pro
Sheet Author
API Scripter
Ray said: Cassie said: Do you have an <input> for the STR attribute? It can be visible as part of the sheet or type=hidden.  No...the STR attribute is being calculated from the STRbase and the STRXP attributes as follows: You need to have an input for STR on the character sheet. I'm pretty sure a sheet worker created attribute wont output to the attributes and abilities tab unless an input for it exists on the character sheet. Honestly, if you are creating character sheet, you should be using that as your primary interface, not the attributes & abilities tab. The attributes part of that tab is a legacy feature, and really is only meant to be used by people who aren't using a character sheet (or for stuff the character sheet doesnt provide).
1547970702
Jakob
Sheet Author
API Scripter
GiGs said: Ray said: Cassie said: Do you have an <input> for the STR attribute? It can be visible as part of the sheet or type=hidden.  No...the STR attribute is being calculated from the STRbase and the STRXP attributes as follows: You need to have an input for STR on the character sheet. I'm pretty sure a sheet worker created attribute wont output to the attributes and abilities tab unless an input for it exists on the character sheet. It will still show/exist/be able to be set to a value even if you don't have an input. That having been said, I would give every attribute at least a hidden input so that it gets a default value (instead of an undefined default).
1547971602
GiGs
Pro
Sheet Author
API Scripter
I agree it will exist, and can be called by macros, etc. But will it be assigned to the attributes tab without a defined input?
1548002630
Jakob
Sheet Author
API Scripter
GiGs said: I agree it will exist, and can be called by macros, etc. But will it be assigned to the attributes tab without a defined input? Yes.
1548018712
GiGs
Pro
Sheet Author
API Scripter
Good to know! Back to the drawing board for figuring out OP's problem :)
Thanks everyone...I am still working on this...much appreciated...will post again if need be.