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

[Help] Evaluating a roll without printing.

Is there a way for me to call the API and get the results of a roll, for example; "3d6" I need to know the result of the roll before I send it to chat so that I can determine the margin of success, and print it alongside.
1402774353
The Aaron
Roll20 Production Team
API Scripter
You pass a function as a 3rd parameter to the sendChat() function, and the result is passed to it. Here's Riley's example from the api docs. sendChat("Riley", "/roll 1d20+4", function(ops) { // ops will be an ARRAY of command results. var rollresult = ops[0]; //Now do something with rollresult, just like you would during a chat:message event... }); See the bottom of: <a href="https://wiki.roll20.net/API:Chat" rel="nofollow">https://wiki.roll20.net/API:Chat</a> for more info
Hmm, it's not ideal since I want to include my results in the chat message I send. But I guess it'll have to do, thanks.
1402784975
The Aaron
Roll20 Production Team
API Scripter
You can certainly include the numeric results. If you want to have the same tooltip behavior with dice results, you can look at Honey Badger's Power Cards script. It recreates the tooltip style pretty accurately (and even extends it a bit). The function is pretty well extracted from the rest of the code, so it wouldn't be too hard to use it.
Well, if I call sendChat, and then get the results of the inline rolls from the callback. Then I'd have to call sendChat again to print whatever math I did with those results. The problem is simply that I'll have to send two chat messages, and I was hoping to send only one.
1402845045
The Aaron
Roll20 Production Team
API Scripter
Sending 2 chat messages isn't that big a deal, especially because the first one never goes to the chat.
Oh it doesn't? Great then, problem solved. Thanks a lot. :)
1402871789
Lithl
Pro
Sheet Author
API Scripter
Other options: Use randomInteger to generate the dice results yourself, and perform whatever other math is needed for the roll in your JavaScript code. Or, send an inline roll to the API and parse out the msg.inlinerolls property.
1403026807
Chad
Plus
Sheet Author
Here is a code snippet to roll a number of dice. Pass it two variables: rolls - number of dice to roll die - number of sides on the die roll=0; for (x=0;x&lt;rolls;x++) { this_roll=randomInteger(die); roll += this_roll; } //End die roll FOR loop return roll;
1406018948

Edited 1406020761
sendChat("Riley", "/roll 1d20+4", function(ops) { // ops will be an ARRAY of command results. var rollresult = ops[0]; //Now do something with rollresult, just like you would during a chat:message event... }); Is there not some easy syntax that will allow the array of results to be automatically printed to the chat window, just as it would have been if the overload callback function had not been specified? They could not have left something like that out... I just want it to dump the results, as normal, to the chat window at the end of my callback. Or, to put it another way: instead of a callback to intercept the results INSTEAD OF the chat window, can't we intercept results AND log to the chat window?
1406026612
The Aaron
Roll20 Production Team
API Scripter
It's one or the other. You can of course use /direct to send formatted output that looks like the die roll would have to the chat. It's a little complicated, but not overly so. HoneyBadger's power card script does this with the help of some roll parsing logic Brian wrote. I'd suggest taking a look at that script for ideas on how.
OK cool thanks! &lt;3