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

Custom Sheet: Multiplying two fields that are dice rolls...

Okay, I have two fields that receive dice (1D6, 1D8, etc). I need the two fields to be multiplied.   Field 1 = 1D6 Field 2 = 1D12 These fields are manually filled. As a macro it works. In the chat box I can simply do [[1D6*1D12]] and that works. But not in javascript Here's the on(change I have for it. // Watching for when rangedweapon change on('change:rangedWeapon change:rangedDamage change:rangedHitBonus change:rangedPenetrationPlus change:rangedRoF change:rangedAmmunition change:rangedAmmunition_max change:rangedRange change:rangedSkill change:ranged_rf', function(eventInfo) {     getAttrs(['rangedWeapon', 'rangedDamage', 'rangedHitBonus', 'rangedPenetrationPlus', "rangedRoF", "rangedAmmunition", 'rangedAmmunition_max', 'rangedRange', 'rangedSkill',], function(values) {         let textToChat = "&{template:default}";          textToChat = textToChat.concat(" {{name=" + values.rangedWeapon + "}}");         textToChat = textToChat.concat(" {{Hit= [[1d20+" + values.rangedHitBonus + "]]}}");         textToChat = textToChat.concat(" {{Damage= [[" + values.rangedDamage + "]]}}"); // in this section I was trying to add 2 lines, first for the attack roll, the 2nd to add the damage // //     textToChat = textToChat.concat(" {{Rapid Fire= [[1d20+" + values.rangedHitBonus + "]]}}"); //     textToChat = textToChat.concat(" {{Damage= [[" + values.rangedDamage * values.ranged_rf + "]]}}"); // I couldn't get it to work, because I don't know the lingo to multiply in this specific syntax!!!         textToChat = textToChat.concat(" {{Penetration= " + values.rangedPenetrationPlus + "}}");         textToChat = textToChat.concat(" {{Ammunition= " + String(parseInt(values.rangedAmmunition)-1) + " / " + values.rangedAmmunition_max + "}}");         console.log(textToChat);         setAttrs({ rangedRoll :         textToChat });     }); }); Thanks in advance!
1646293972

Edited 1646293995
vÍnce
Pro
Sheet Author
what if you quote "*" like so? textToChat = textToChat.concat(" {{Damage= [[" + values.rangedDamage + "*" + values.ranged_rf + "]]}}"); Treat the asterisk like text.
1646294256

Edited 1646295157
vÍnce
Pro
Sheet Author
You also might consider using template literals which would make your macros a little easier to construct in js. (uses backticks instead of quotes and use a ${var} format to call variables)  Which should look a little closer to how we write these macros in roll20. Like so; textToChat = textToChat.concat(`{{Damage = [[${rangedDamage}*${ranged_rf}]]}}`);
vÍnce said: what if you quote "*" like so? textToChat = textToChat.concat(" {{Damage= [[" + values.rangedDamage + "*" + values.ranged_rf + "]]}}"); Treat the asterisk like text. My sheet looks like this: Note the Damage box and the R.F. Box And the chat box result of clicking on "Fire" which should spit out both just damage & damge * R.F. fields.
vÍnce said: You also might consider using template literals which would make your macros a littler easier to construct in js. (uses backticks instead of quotes and use a ${var} format to call variables)  Which should look a little closer to how we write these macros in roll20. Like so; textToChat = textToChat.concat(`{{Damage = [[${rangedDamage}*${ranged_rf}]]}}`); That was it! Well, kinda.  I used @ instead of $ textToChat = textToChat.concat(`{{Damage = [[@{rangedDamage}*@{ranged_rf}]]}}`); Thank you!!!!
1646294973

Edited 1646295071
vÍnce
Pro
Sheet Author
  lol.  @{...} would call the attribute directly and I suppose that works just as well. maybe one of the js gurus can explain why the template literal wasn't grabbing the the appropriate values as well...?
That'd be nice! I tried the $ first and it didn't take... wonky
1646318122
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
If you were just doing this: textToChat = textToChat.concat(`{{Damage = [[${rangedDamage}*${ranged_rf}]]}}`); You need to get the attribute values from the values object: textToChat = textToChat.concat(`{{Damage = [[${values.rangedDamage}*${values.ranged_rf}]]}}`);
1646320074
vÍnce
Pro
Sheet Author
"values object" I knew/know that...  My js experience in a nutshell. ;-)  thanks Scott