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

sendChat inline roll result instead of total

Hello, Im having trouble figuring out how to get the inline roll result of my sendChat function, im able to get the total via > ops[0].inlinerolls[0].results.total but this just adds all of the rolls together instead of retrieving the actual result i.e. 2d6kl1 + 1d4 + 1d4 rolls as (1+3) + (1) + (2) and i get a total of 7 instead of the result i want which is 4 because of keeping the lowest die of 2d6. CODE: sendChat("Terry", " rolled [[ 2d6kl1 + 1d4 + 1d4 ]] for initiative!", function(ops){ log(ops[0].inlinerolls[0].results.total) }
1519355992
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Parsing inline rolls is a pain. I would recommend using the  randomization functions (especially randomInteger(), which still uses the quantum roll system) to be able to work with the results in pure javascript and then send everything to chat when it is ready for output.
Is it not possible to just get the results of a roll, inline or othewise from the sendChat function? "Total" just adds all the values rolled together but is not the true result.
1519393519
The Aaron
Pro
API Scripter
It's possible, it's just complicated.&nbsp; Read the documentation in the first part of this page:&nbsp; <a href="https://wiki.roll20.net/API:Chat" rel="nofollow">https://wiki.roll20.net/API:Chat</a> That describes the format of the msg.inlinerolls structure..
I was actually able to dig some more and find a solution actually made by you here , thanks! function returns the original message with all the inline roll results, for my specific use cause i only ever use one such inline so i strip everything else off the message. sendChat("Riley", " [[roll 1d20+4]]", function(ops) { var rollresult = getRollResult(ops[0]); }); function getRollResult(msg) { log("Obtaining roll result...") if(_.has(msg,'inlinerolls')){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg.content = _.chain(msg.inlinerolls) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.reduce(function(m,v,k){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m['$[['+k+']]']=v.results.total || 0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return m; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},{}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.reduce(function(m,v,k){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return m.replace(k,v); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},msg.content) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.value(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //removes all non-numerical characters and returns result &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return msg.content.replace(/\D/g,''); &nbsp;&nbsp;&nbsp;&nbsp;} }
1519399771
The Aaron
Pro
API Scripter
How about that!&nbsp; =D&nbsp; Glad you got it sorted out.