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

How do I send a Quantum Roll into chat?


Edited 1667047787
I'm very tired, so I'll keep this concise. What I'm trying to do with my script 1. Use Roll20's Quantum Roll to roll a 1d10. 2. Store results to manipulate some conditionals of a broken sheet template. 3. Re-use the same Roll objects in the template I understand that: &nbsp; &nbsp; -randomInteger() is an option for me to use instead of quantum roll (and that works) &nbsp; &nbsp; -The current version of my code doesn't work and somewhat why &nbsp; &nbsp; -The solution probably involves using a callback function in a sendChat() call &nbsp; &nbsp; -How do I affect variables outside of a sendChat() scope? quantum_regular_rolls for example doesn't maintain its pushes outside. What I hope to learn If I have a rollid, how do I send the roll object into chat? An identical duplicate, with the same source, rollid, result, etc. Is the process any different between inline rolls and /roll? What I'm currently using The lines of interest start from line 87. Here's the gist: &nbsp; <a href="" rel="nofollow"></a> Please treat me well!
API Scripter
Hey, kookie... A few things... First, the randomInteger function also uses the quantum roll server, so the values are just as random, though they don't produce an actual roll that gets formatted in the chat output. Second, there is no way to "reobtain" a roll via the roll ID (at least not from the sandbox). You have to keep all of the roll to do something like that.&nbsp; Third, the inlinerolls property of a message object is itself an array of all the rolls in the message, so I'd think you'd have to pull the result you want from item [0]. That may be why you're not retaining the value. Finally, if what you want is to have the roll appear in chat with the proper formatting and roll tip of an inline roll, that is a matter of HTML spans and classes. You don't *need* a full inline roll do do that... You just have to know what information to put where in the series of spans so that it is formatted how you want. If you want to learn how to do that, look at libInline and how it builds a roll tip from each of the component parts of the roll object. But, if you're looking at libInline, you might as well try plugging it in to see if it can get the data you want to get from your roll. It will parse the roll for you and hand back a new object with easy handle for value, crit dice, etc, AND it will let you get the roll tip to insert in your message so your users see the hover info.
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Tim's got great advice. I'll add one edit, and hit some of your questions that I think he missed. The edit: randomInteger() does not actually use quantumRoll. It uses Roll20's backup RNG system that they used before the advent of quantumRoll. As far as such a thing can be determined, it is still "more" random than the default JS Math.random() &nbsp;method, but it's important to remember it is not the same The way to extract the results of the sendChat callback into your main function is to use async/await and Promises. For your use case, this would something like this: on('chat:message', async (msg) =&gt; {//Switched to an arrow function as it's more condensed. The async tag tells JS that this is an asynchronous function and will pause when we await things. // lines 16 - 89 as you had them in your code const all_regular_rolls = await Promise.all(//Await this promise, which will resolve when all of the rolls are rolled. [...Array(regular_rolls).keys()].map(()=&gt;{ return new Promise(resolve =&gt; { const rollresult = ops[0]; sendChat('','[[1d10]]',(ops)=&gt;{ // Will set it to the result's value wrapped in inline roll brackets resolve(`[[${JSON.parse(rollresult.inlinerolls).total}]]`); }); }); }) ); const all_hunger_rolls = await Promise.all(//Await this promise, which will resolve when all of the rolls are rolled. [...Array(hunger_rolls).keys()].map(()=&gt;{ return new Promise(resolve =&gt; { const rollresult = ops[0]; sendChat('','[[1d10]]',(ops)=&gt;{ resolve(`[[${JSON.parse(rollresult.inlinerolls).total}]]`); }); }); }) ); // Your code from line 124 - 151 while (all_regular_rolls.length &lt; 15) { all_regular_rolls.push("[[1d10]]"); } while (all_hunger_rolls.length &lt; 5) { all_hunger_rolls.push("[[1d10]]"); } // Your second sendChat, but replace `quantum_TYPE_rolls` with `all_TYPE_rolls`, e.g. `quantum_regular_rolls` becomes `all_regular_rolls` // This will not show the previously rolled rolls as true inline rolls, but will show the result properly. }); The above is how you'd do this in the API, but I notice that you are using a roll template that doesn't appear in the roll20 character sheet repo, so I'm assuming you are using a custom character sheet. The better way to handle this would be to build this functionality directly into the character sheet using Custom Roll Parsing . This would allow you to properly manipulate these values and retain the true quantum roll styling.

Edited 1667059545
Thank you both for the amazing and quick replies.&nbsp; I'll give this another shot thanks to you. Last night was my first time coding in JS, so I'm still a newbie. Yes, the character sheet I'm using is a custom one, but it's not mine. It is Roll20's Vampire The Masquerade character sheet, which is not open source and in a private repository. I had already asked for its HTML layout and CSS Style, but I was told because of contracts and such it could not be shared. I also agree: the better way would be to build it directly into the character sheet. But I feel more comfortable coding than writing HTML from almost-scratch (seeing as I've never done it before), so here we are. I'll submit another post about the result when I get the chance.
Took a while. Had to learn how promises worked and a lot of JS syntax to understand what to fix. Played with Tim's libInline. Fun to use, but not applicable to this character sheet template, at least from the time I spent dabbling in it. Code that works:&nbsp; <a href="" rel="nofollow"></a> Thanks for the help.