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

Calculation in Value won't add up

So I am still pretty new to all this but I am trying to modify the existing Dark Heresy Second Edition Character sheet to utilize the !roll40k script that was created. Unfortunately when I run it, as coded below, it only grabs the base AcrobaticsCharacteristic and does not do the subtraction/addition that follows it. Can anyone help me understand where I am going wrong? <tr> <td> <div> <div style="width:60%"> <button name="roll_Acrobatics" type="roll" value="/em @{alias_name} makes a Acrobatics Check!\n!roll40k @{alias_name},@{AcrobaticsCharacteristic}+@{Acrobatics1}+@{Acrobatics2}+@{Acrobatics3}+@{Acrobatics4}-20,?{Total Modifiers|0}"> <label>Acrobatics</label> </button> </div> <div style="width:40%"> <select name="attr_AcrobaticsCharacteristic"> <option value="@{Agility}">(Ag)</option> <option value="@{Strength}">(S)</option> </select> </div> </div> </td> <td><input name="attr_Acrobatics1" type="checkbox" value="20"></td> <td><input name="attr_Acrobatics2" type="checkbox" value="10"></td> <td><input name="attr_Acrobatics3" type="checkbox" value="10"></td> <td><input name="attr_Acrobatics4" type="checkbox" value="10"></td> </tr>
1417476511
Lithl
Pro
Sheet Author
API Scripter
I'm not familiar with the roll40k script, but I suspect your issue is there. Scripts have to parse their own input, and if the script in question wasn't written to handle the addition, it won't work no matter how you construct the macro. Could you link to the script you're using?
Sure, I wrote the script so I could modify it, I was just hoping not to have to. !roll40k script
1417545331
Lithl
Pro
Sheet Author
API Scripter
Yeah, that script is assuming "attribute" is a single number. parseInt(AcrobaticsCharacteristic+Acrobatics1+Acrobatics2+Acrobatics3+Acrobatics4-20) isn't going to do what you expect. You're going to need to parse it as an expression in some way. The easiest and safest solution would probably be to check if it's an inline roll, and take the result. So your macro would then be !roll40k @{alias_name},[[@{AcrobaticsCharacteristic}+@{Acrobatics1}+@{Acrobatics2}+@{Acrobatics3}+@{Acrobatics4}-20]],?{Total Modifiers|0} .
I did try that earlier, but it results in a NaN Warklaw (GM) Caster makes a Acrobatics Check! Warklaw (GM): Caster has a modified target of NaN and rolled a 37 . Caster fails by NaN degree(s) . I am thinking I may just need to modify the script to accept additional parameters.
So I did go ahead and create a new script for use with this Character sheet and skills, and it works great. That said I think I can make it better by modifying the character sheet slightly and then the script so that you only need one additional parameter rather than 4. I will work on that next. /** * This script rolls a d100 and computes and outputs the success results based * on Dark Heresy Second Edition RPG criteria. It is intended to be used for skill * checks. * * The following commands is used: * !skill40k [tokenName], [attributeValue], [skillBonus1], [skillBonus2], [skillBonus3], [ModifierValue] **/ //Rolls a d100 and calculates the success or fail results to the chat window. var rollResult = function(token, attribute, skillBn1, skillBn2, skillBn3, skillBn4, modifier) { var roll = randomInteger(100); var skillBonus = parseInt(skillBn1) + parseInt(skillBn2) + parseInt(skillBn3) + parseInt(skillBn4) - 20; var modTarget = parseInt(attribute) + skillBonus + parseInt(modifier); var output1 = token + ' has a modified target of <B>' + modTarget + '</B> and rolled a <B>' + roll + '</B>. '; var output2 = ''; var output3 = ''; var autoRoll; var degOfSuc; //Check for an automatic result switch (roll) { case 1: autoRoll = 1; break; case 100: autoRoll = 100; break; default: autoRoll = 0; } //Form output message based on result if(roll <= modTarget) { if(autoRoll === 100){ output2 = '<span style="color:red">' + token + ' rolled a 100 and automatically fails by <B>1 degree</B>.</span> '; } degOfSuc = (Math.floor(modTarget/10) - Math.floor(roll/10)) + 1; output2 = '<span style="color:green">' + token + ' succeeds by <B>' + degOfSuc + ' degree(s)</B>.</span> '; } else { if(autoRoll === 1) { output2 = '<span style="color:green">' + token + ' rolled a 1 and automatically succeeds by <B>1 degree</B>.</span> '; } degOfSuc = (Math.floor(roll/10) - Math.floor(modTarget/10)) + 1; output2 = '<span style="color:red">' + token + ' fails by <B>' + degOfSuc + ' degree(s)</B></span>. '; } //Return output var output = output1 + '<br><br>' + output2 + output3; return output; } /** Interpret the chat commands. **/ on('chat:message', function(msg) { var cmdName; var msgTxt; cmdName = '!skill40k '; msgTxt = msg.content; if(msg.type == 'api' && msgTxt.indexOf(cmdName) !== -1) { var paramList = msgTxt.slice(cmdName.length); if(paramList.indexOf(',') == -1) { sendChat(msg.who, '/w ' + msg.who + ' must specify seven comma-separated parameters for !skill40k command.'); } else { var paramArray = paramList.split(','); var curToken = trimString(paramArray[0]); var attribute = trimString(paramArray[1]); var skillBonus1 = trimString(paramArray[2]); var skillBonus2 = trimString(paramArray[3]); var skillBonus3 = trimString(paramArray[4]); var skillBonus4 = trimString(paramArray[5]); var modifier = trimString(paramArray[6]); var result = rollResult(curToken, attribute, skillBonus1, skillBonus2, skillBonus3, skillBonus4, modifier); sendChat(msg.who, result); } } }); /** Trims a string **/ var trimString = function(src) { return src.replace(/^\s+|\s+$/g, ''); }
1417559907
Lithl
Pro
Sheet Author
API Scripter
Warklaw said: I did try that earlier, but it results in a NaN Warklaw (GM) Caster makes a Acrobatics Check! Warklaw (GM): Caster has a modified target of NaN and rolled a 37 . Caster fails by NaN degree(s) . If you're talking about my suggestion to use inline rolls, that's because in msg.content the inline roll is replaced by something along the lines of $[[0]]. (Which is, as you've discovered, not a number.) You would have to modify the script to inspect msg.inlinerolls to find the correct result value. (Note that msg.inlinerolls is only defined if there is one or more inline rolls in the message.)
Thanks I will explore that.