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

Back-End Die Rolling

1580992621

Edited 1580992683
GM Michael
API Scripter
Is there a way to have the API perform a roll parse?  Say I've had a user input the string "1d4+1" and would like to use that in an internal calculation.  Without writing my own roll parser from the ground up or using sendChat('[[1d4+1]]') to pump it to chat, is there any way to resolve that to a particular roll? Is there perhaps some service or existing library that'll do it?
1580994443
The Aaron
Roll20 Production Team
API Scripter
You do that with sendChat() and the optional callback parameter: sendChat('', `[[${yourRollTextVariable}]]`,(rollArray)=&gt;{ /* do stuff */}); Note that this is an asynchronous call, so code appropriately. See:&nbsp; <a href="https://wiki.roll20.net/API:Chat#sendChat.28speakingAs.2C_input_.5B.2Ccallback_.5B.2C_options.5D.5D_.29_.5BAsynchronous.5D" rel="nofollow">https://wiki.roll20.net/API:Chat#sendChat.28speakingAs.2C_input_.5B.2Ccallback_.5B.2C_options.5D.5D_.29_.5BAsynchronous.5D</a>
Right, but that would show it to the user, yes? I'd prefer something silent. I guess... Would that work if you whispered to a non-existent character?
1581056399
GiGs
Pro
Sheet Author
API Scripter
no, when using sendChat with a callback, it doesnt get displayed in chat.
Oh!&nbsp; Well, awesome, thanks!