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.

August 08 (7 years ago)

Edited August 08 (7 years ago)
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.

August 09 (7 years ago)
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.

August 09 (7 years ago)
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.

August 09 (7 years ago)
GiGs
Pro
Sheet Author
API Scripter

I see what you meant now. That makes sense.