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

Rolling Dice from inside an API script

Hi all.  I am curios if there is a way to access Roll20 dice roller from inside an API script, or do I need to write my own random function. What I am planning to do is to roll a specific dice formula and save the result to a variable, so that I can use this in follow up calculations.
1533720355

Edited 1533720369
Jakob
Sheet Author
API Scripter
There is a synchronous  randomInteger()  function which you can use – documentation in the wiki –, which will just give you a random number. If you need the full power of the dice roller, you can use sendChat() with a callback and parse the message object you receive, but this is asynchronous, so it needs a bit more care to deal with (it also has some unaddressed bugs you may or may not run into).
Thank you for the information ! I think I will be able to work from here.
1533807086
GiGs
Pro
Sheet Author
API Scripter
Doesn't randomInteger use the same rng as the dice roller? I thought I read it was the same system, put in a function for scripting. I may be misremembering.
1533808202
Jakob
Sheet Author
API Scripter
G G said: Doesn't randomInteger use the same rng as the dice roller? I thought I read it was the same system, put in a function for scripting. I may be misremembering. I think so, but it just gives you a random integer, no roll expressions or anything like that, so you would have to build your own function to interpret the random number.
1533808459
GiGs
Pro
Sheet Author
API Scripter
I see what you meant now. That makes sense.