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 .
D&D 2024 has arrived! Pre-order the new core rulebooks now and get an exclusive pre-order bonus for free!
Create a free account

script syntax question

Hello -- I have what I'm fairly sure is a formatting question. Creating a custom character sheet. Stats have action modifiers. there can be temporary adjustments to those modifiers. For the button to make the rolls, I'm using a hidden variable.  The first part of my script (setting the action modifier based on the attribute score) works like a champ (should look familiar to most everyone). The second part, calculating the hidden variable based on the action modifier and action modifier adjustment is where I'm running into an issue. The script updates the hidden variable, but with 0 (I did some testing and they ARE updating). I've bolded the lines where I'm pretty sure I have a syntax issue making 'base' and 'adj' 0 instead of the actual values). Or maybe it is the getattrs? I'll happily take an answer, but if anyone can point me to a reference I'd really appreciate it. Thanks!     const stats = ['STR','DEX','CON','INT','PRE','AWR','WIT'];     stats.forEach(stat => {         //update base action modifier (this part works great) on(`change:${stat} sheet:opened`, () => {     getAttrs([stat], v => {         const score = parseInt(v[stat]) || 0;         const modifier = setam(score);               setAttrs({[`${stat}_act`]: modifier});             });         });         //set hidden action modifier value (I've dorked up something here) on(`change:${stat}_act change:${stat}_act_adj sheet:opened`, () => {     getAttrs(['${stat}_act', '${stat}_act_adj'], v => {         const base = parseInt(v['${stat}_act']) || 0;         const adj = parseInt(v['${stat}_act_adj']) || 0;                 const update = (base + adj)                 setAttrs({[`${stat}_actuse`]: update});     }); });});
Solved it (thanks to a completely unrelated post). The issue was using ' instead of ` to define the template literals. fixed bits getAttrs([`${stat}_act`, `${stat}_act_adj`], v => {         const base = parseInt(v[`${stat}_act`]) || 0;         const adj = parseInt(v[`${stat}_act_adj`]) || 0;