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

[Request] Roll function

1367756655
Alex L.
Pro
Sheet Author
Riley would it be possible to have a function that just returns the result of a roll? Something like: var result = roll("2d6");
You can use Javascript's Math.random() property to accomplish this on your own, although writing a whole parser is a bit complex. &nbsp;I have one here:&nbsp; <a href="https://github.com/TableMUSH/NodeBot-Dice/blob/master/Parsers/dd.js" rel="nofollow">https://github.com/TableMUSH/NodeBot-Dice/blob/master/Parsers/dd.js</a> , which relies on this parent class:&nbsp; <a href="https://github.com/TableMUSH/NodeBot/blob/master/Lib/Parser.js" rel="nofollow">https://github.com/TableMUSH/NodeBot/blob/master/Lib/Parser.js</a> &nbsp;and this Tokenizer class:&nbsp; <a href="https://github.com/TableMUSH/NodeBot/blob/master/Lib/Tokenizer.js" rel="nofollow">https://github.com/TableMUSH/NodeBot/blob/master/Lib/Tokenizer.js</a> &nbsp;and this Token class:&nbsp; <a href="https://github.com/TableMUSH/NodeBot/blob/master/Lib/Token.js" rel="nofollow">https://github.com/TableMUSH/NodeBot/blob/master/Lib/Token.js</a> All of this could be converted to Roll20 (except that you'd want to go back to using Math.random() instead of random.org, since we can't do Ajax on Roll20), especially given we know the scripts get concatenated together, which means they can probably reference one another's global namespaces. Alternatively, a roll() function would be a nice and easy way to bundle this up. :)
1367781274
Alex L.
Pro
Sheet Author
No point in using Math.random() if I thought there was any point in it i would have used it and not bothered asking. only was to make sure your rolls are as fair as roll20s is to use roll20s. Also last i checked Math.random() is not very random.
At some point in the future I will probably expose Roll20's random number generator to the API so you can use it to generator random integers if you wish (e.g. randomInt(20) gives you a random integer between 1 and 20).&nbsp; I can also probably add a function which will work with the full dice engine so you could perform any roll that you can through Roll20 (e.g. "3d6!&gt;4"). The result it returned would be a complex object like the one you get from chat:message events. Which are you looking for?
1367781578
Alex L.
Pro
Sheet Author
I would prefer the full dice engine if that would be possible. I plan on implementing some forms of conditional rolls, but i dont want to have to wait for incoming roll callbacks over the chat system.
Alex L. said: I would prefer the full dice engine if that would be possible. I plan on implementing some forms of conditional rolls, but i dont want to have to wait for incoming roll callbacks over the chat system. Okay, will do.
1367781713
Alex L.
Pro
Sheet Author
Thanks as always for your hard work Riley.
I concur, working on a WEG star wars campaign and need to code in the 'wild die' mechanics?
1368229386
Konrad J.
Pro
API Scripter
Riley D. said: At some point in the future I will probably expose Roll20's random number generator to the API so you can use it to generator random integers if you wish (e.g. randomInt(20) gives you a random integer between 1 and 20).&nbsp; I can also probably add a function which will work with the full dice engine so you could perform any roll that you can through Roll20 (e.g. "3d6!&gt;4"). The result it returned would be a complex object like the one you get from chat:message events. Which are you looking for? Hi Riley, just wondering when the Roll20 Dice routines would be available to the API? All I really need at this moment is the simple one you talked about. &nbsp;I just want to get a random number for d6 for a custom dice script I'm working on. If its not going to be for a while, whats the best way to&nbsp;implement&nbsp;our own random number generator? &nbsp;For now I'll just use the math routines so I can keep on coding and then replace that with whatever you come up with! Thanks
Something like this would be totally cool!
It will be "soon" (within the next few days).