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() 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) => {//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(()=>{
return new Promise(resolve => {
const rollresult = ops[0];
sendChat('','[[1d10]]',(ops)=>{
// 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(()=>{
return new Promise(resolve => {
const rollresult = ops[0];
sendChat('','[[1d10]]',(ops)=>{
resolve(`[[${JSON.parse(rollresult.inlinerolls).total}]]`);
});
});
})
);
// Your code from line 124 - 151
while (all_regular_rolls.length < 15)
{
all_regular_rolls.push("[[1d10]]");
}
while (all_hunger_rolls.length < 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.