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 Help (AGAIN)

So I am still plugging away at my Castles and Crusades custom character sheet. I am trying to auto populate the monk's unarmed combat damage die based on class and level. This is what I have and it doesn't work. <script type="text/worker"> on("change:level change:monkdmg sheet:opened", function() {          getAttrs(["Level","MonkDmg"], function(values) {     let level = parseInt(values.Level)||0;     let modifier;     // the scale    if (level === 1) modifier ? "1d4" :     if (level === 2) modifier ? "1d6" :     if (level === 3) modifier ? "1d6" :     if (level === 4) modifier ? "1d8" :        if (level === 5) modifier ? "1d8" :         if (level === 6) modifier ? "1d8" :       if (level === 7) modifier ? "1d10" :       if (level === 8) modifier ? "1d10" :        if (level === 9) modifier ? "1d10" :        if (level === 10) modifier ? "1d10" :         if (level === 11) modifier ? "1d10" :        if (level === 12) modifier ? "1d10" :        if (level === 13) modifier ? "1d10" :        if (level === 14) modifier ? "1d10" :       if (level === 15) modifier ? "1d10" :        if (level === 16) modifier ? "1d10" :       if (level === 17) modifier ? "1d10" :        if (level === 18) modifier ? "1d10" :     if (level === 19) modifier ? "1d10" :        if (level === 20) modifier ? "1d10" :        setAttrs({MonkDmg : modifier});  }); }); </script>
1620154959

Edited 1620155032
Andreas J.
Forum Champion
Sheet Author
Translator
maybe those colons are a problem. Also, using an if - else if structures seems advisable. Example of a similar code block that's working: <a href="https://github.com/Roll20/roll20-character-sheets/blob/f02a37ecb2defd2de5a473862e52fd89fd46a638/Feast_of_Legends/feast_of_legends.html#L157" rel="nofollow">https://github.com/Roll20/roll20-character-sheets/blob/f02a37ecb2defd2de5a473862e52fd89fd46a638/Feast_of_Legends/feast_of_legends.html#L157</a>
1620156377
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, you're trying to combine if statements and ternary. It needs to be one or the other and this is a better place to use I'd/else, or maybe a switch.
I read all these links and articles people provide and I just don't get it. Knowing what my intent is, how would you write it?
1620157271

Edited 1620157932
Andreas J.
Forum Champion
Sheet Author
Translator
just copupaste the version I linked you, and replace the variables to the ones you're using. Here is how I'd do it, using my linked code as a base: if (level &gt;= 7) modifier = "1d10"; else if (level &gt;= 4) modifier = "1d8"; else if (level &gt;= 2) modifier = "1d6"; else if (level === 1) modifier = "1d4"; else modifier = "1d4";
Ah. Ok. I will practice this format and hopefully begin to understand the difference.&nbsp;
Worked brilliantly. Thank you. I will add it to my stash of stolen code.