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

Roll a number of dice equal to an ability score

I have been trying to get a macro to roll a number of d6s equal to my character's proficiency bonus, but something like /r @{PB}d6 doesn't work. It returns a  TypeError: Cannot read property 'substring' of undefined error. I don't know if there is actually a way to do this since most dice rolls generally add the bonus instead of this. I have a basic macro that will work in the meantime, but I am still curious about whether something like this can be done.
1591736471
GiGs
Pro
Sheet Author
API Scripter
That code will work if there's an attribute named PB, and you are using it as a character Ability. If you're just typing that in chat, or setting up a universal macro, you need to tell roll20 which character's PB stat to use. The two most common ways: /r @{selected|PB}d6 /r @{Frodo|PB}d6 selected works if you have a token representing a character, and have it selected. Frodo works if you have a character named Frodo.
I tried that, but it would only come out to be the proficiency bonus. I made an attribute and tried giving the value of @{PB} (I know it exists because it is referenced by other attributes) and just the number 2 (my character's current proficiency bonus), all results came out to be the same every time. So unless I am that unlucky in that I'm getting the same number after multiple tests, I think I have something wrong somewhere.
1591738282
GiGs
Pro
Sheet Author
API Scripter
If PB only come out to the proficiency bonus, then thats what the PB represents on that sheet. By creating another attribute with the same name, you have likely overwritten the PB on the sheet.  What attribute are you expecting it to be?
1591738700

Edited 1591739202
PB is supposed to represent proficiency bonus, and it is, but when I run the command the roll always comes out as PB and not PB number of d6s Sorry, I probably should have explained what I meant by that the first time. Edit: I tested your first command in another game and it worked just fine, I am now confused as to why it doesn't work in this one. Does the game using a different character sheet style to the standard and 5e one make a difference as to how proficiency bonus is stored?
1591739106
GiGs
Pro
Sheet Author
API Scripter
I'm not quite following. Can you post a screenshot of what you get in chat when you use /roll @{selected|PB}d6 Also, which character sheet are you using?
You need to be sure to tell it whose PB to be using. And is it PB or pb (I forget if case matters here)? Are you sure the token is set to represent a character sheet? Are you then selecting that token and using @{selected|PB} ?
1591739392

Edited 1591739464
That is what the result is when I run the command in this game. This game is using a different style of dnd 5e character sheet that I'm not used to, its labeled as the following image: 
1591740390
GiGs
Pro
Sheet Author
API Scripter
That's an autocalc field. It looks like the way the brackets are arranged is confusing roll20 and it's not being interpreting as a number. I do wonder about that autocalc accuracy - why would something need to be divided by 1 million? Try wrapping it in [[ ]] like /roll [[@{selected|PB}]]d6 This will force it to be evaluated as a number. Hopefully it works!
1591740787

Edited 1591740935
That worked! If I hover over the calculation it still shows a mess of math, but it works now. Thank you, it is crazy how something so confusing gets fixed by the simplest of solutions. Edit: When I fixed the formatting the mess went away, and it still works.
1591741279
GiGs
Pro
Sheet Author
API Scripter
Great! I found the sheet and honestly cant understand why the calculation is built the way it is. But this solution works, so no need to worry about it :) If you dont want to see th calulcation when you hover hover it, try doubling up the inline roll brackets: /roll [[ [[@{selected|PB}]] ]]d6 The spaces there aremn't necessary, just to make it more readable. You could also use a rolltemplate, like &{template:default} {{name=Name You Want To Appear At The Top}} {{PB=[[  [[@{selected|PB}]]d6 ]]}}  This will show the sum of the dice, and when you mouse over it will show the individual dice but should hide the big calculation. That sheet has a rolltemplate of its own, which might look prettier. I think  this will work, but i didnt want to spend a lot of time trying to interpret the code :) &{template:5eDefault} {{title=Name You Want To Appear At The Top}} {{PB=[[  [[@{selected|PB}]]d6 ]]}} 
I put it into a template for simplicity's sake, I use quite a few macros so it makes it easier to tell what's being rolled if they are labeled by a template. I will say though, this irked me more than it should have. I write code for a living and not being able to solve a problem this small was more than aggravating. I felt like I pulled the rookie mistake and left out the semicolon at the end of a line of code.
1591741966
GiGs
Pro
Sheet Author
API Scripter
Dont punish yourself :) I was able to see a solution purely due to experience with roll20, it's not obvious if you don't know the system well.