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

API Button to roll a dice

I'm trying to add an API button to Roll Templates for spells so that a player can read the spell description, understand what dice need to be rolled and, if they desire, roll those dice by pressing the button (some people prefer to roll the physical dice).  Thus, I want a command something like this, which both provided the button if people want it, but also shows those rolling physical dice which dice to roll: [Roll 1d4+4](~[[1d4+4]]) Clearly, that won't work as it stands as ~[[1d4+4]] cannot call an Attribute macro, but is there some way of getting the same functionality without having to create a new API (I'm not a programmer) or a macro for every possible dice roll?  There may well be something obvious that I'm missing, but I've searched for it and can't find it. Or is there an API Script someone has created that I could use if I upgraded from Plus to Pro use?
1594115618

Edited 1594115701
Oosh
Sheet Author
API Scripter
Without the API, you would have to create one or more macros. What system/character sheet are you using? You could go with one macro: /r [[?{Number of dice?|1}]]?{Die type|d4|d6} + ?{Modifier?|4} Just a brief example with limited options, but you get the idea. They can just copy the details from the button label. Or you could go with one per die type, or one per modifier type, or one per spell. Depending on the system you're using it may also have templates available that have all those fields included for you to fill in to roll damage. But yes, you do need to link the button to an actual macro. I'm not sure what the API options are though, I'm sure there's something nifty available.
1594116372
Finderski
Pro
Sheet Author
Compendium Curator
You can use an API Command Button like this: [1d4+4](!
/r 1d4+4) The html notation for a carriage return is necessary for this to work and if you open the macro after you save it, you'd have to replace it again, but...this will do what you want. I tried using an inline roll but the results were always weird.
Finderski, that's brilliant!  Works just fine - thanks.  It's great to learn new stuff! Finderski said: You can use an API Command Button like this: [1d4+4](!
/r 1d4+4) The html notation for a carriage return is necessary for this to work and if you open the macro after you save it, you'd have to replace it again, but...this will do what you want. I tried using an inline roll but the results were always weird.
1594119945
Oosh
Sheet Author
API Scripter
Huh, didn't know that worked! I was sure I tried that at some point. You're right about inline rolls though, they definitely break things.
1594131948
Finderski
Pro
Sheet Author
Compendium Curator
Oosh said: Huh, didn't know that worked! I was sure I tried that at some point. You're right about inline rolls though, they definitely break things. I wasn't sure if it was going to work, I just know people had used it for doing some tricky stuff...that trick is what actually lead me to learning about Ability Command Buttons which I use a lot for character sheets. :)
1594132631
Finderski
Pro
Sheet Author
Compendium Curator
By the way, you can get fancier, but you have to use html markup. &nbsp;Here's the wiki page that explains a lot of this stuff:&nbsp;<a href="https://wiki.roll20.net/API:Chat#API_Command_Buttons" rel="nofollow">https://wiki.roll20.net/API:Chat#API_Command_Buttons</a>
1594157021
GiGs
Pro
Sheet Author
API Scripter
If you want to send dice of different types, you can combine Finderski's trick with a query: [Roll ?{Roll String|1d6}](!&amp;#13;/r ?{Roll String}) This will prompt you to enter a dice string (1d6, 1d4+4, 3d6&gt;4, 5d10kh2, or whatever), and it'll send that roll to the chat for the players.
OK, all was going swimmingly and worked really well, until I tried to whisper a button using the &amp;#13; code in the button string.&nbsp; Using such a code in normal chat seems absolutely fine, and works well.&nbsp; However, as soon as you put "/w gm" in front of it, for example as &nbsp;/w gm [Example](!&amp;#13;/r 1d6) You get an error.&nbsp; Does not matter whether this is in the Chat Window, or in a macro, both error.&nbsp; Of course, I'm not trying to use it as simply as that - I'm trying to /whisper a Roll Template containing API Buttons to a character via an Ability macro, so that the Roll Template with the clickable buttons only appears for that character and does not clog up everybody's chat windows. Any other ideas, that don't involve creating an API Script?
1594225175
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I don't think you can easily double up on slash commands like that. You need to escape the second slash so it doesn't try to interpret it right away. Try: /w gm [Example](!&amp;#13;&amp;#47;gmroll 1d6)
1594227197

Edited 1594303294
Richard @ Damery
Pro
API Scripter
Edit: Yep, all works fine now.&nbsp; Thanks for your help, guys! keithcurtis said: I don't think you can easily double up on slash commands like that. You need to escape the second slash so it doesn't try to interpret it right away. Try: /w gm [Example](!&amp;#13;&amp;#47;gmroll 1d6) Hmm.&nbsp; Promising!&nbsp; Certainly that test worked.&nbsp; Now to try it inside a whispered Roll Template API Button.&nbsp; More updates later...