Hi Scott,
I am discovering that I just don't have the right language skills to modify this code to meet my actual needs. Thought I could convert this to a 2 dimensional array and add another input but failed horribly in that attempt. If you have the time (and/or inclination) to help out and update my modification to your code I would appreciate it.
<script type="text/worker">
const extractQueryResult = async function(query){
let queryRoll = await startRoll(`!{{query=[[0[response=?{${query}}]]]}}`);
finishRoll(queryRoll.rollId);
return queryRoll.results.query.expression.replace(/^.+?response=|\]$/g,'');
};
const initiateRoll = async function(event){//Async tag here to allow us to await the various rolls that we're going to do.
let queryResult = await extractQueryResult('Which mod|1|2|3|4|5|6|7|8|9|10');//Await the asynchronous startRoll
const resultSwitchArray =[
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],
[1,50,55,60,65,70,73,76,79,82,85,87,89,91,93,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110],
[2,45,50,55,60,65,68,71,74,77,80,82,84,86,88,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105],
[3,40,45,50,55,60,63,66,69,72,75,77,79,81,83,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100],
[4,35,40,45,50,55,58,61,64,67,70,72,74,76,78,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95],
[5,30,35,40,45,50,53,56,59,62,65,67,69,71,73,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90],
[6,27,32,37,42,47,50,53,56,59,62,64,66,68,70,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87],
[7,24,29,34,39,44,47,50,53,56,59,61,63,65,67,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84],
[8,21,26,31,36,41,44,47,50,53,56,58,60,62,64,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81],
[9,18,23,28,33,38,41,44,47,50,53,55,57,59,61,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78],
[10,15,20,25,30,35,38,41,44,47,50,52,54,56,58,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75],
[11,13,18,23,28,33,36,39,42,45,48,50,52,54,56,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73],
[12,11,16,21,26,31,34,37,40,43,46,48,50,52,54,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71],
[13,9,14,19,24,29,32,35,38,41,44,46,48,50,52,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69],
[14,7,12,17,22,27,30,33,36,39,42,44,46,48,50,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67],
[15,5,10,15,20,25,28,31,34,37,40,42,44,46,48,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65],
[16,4,9,14,19,24,27,30,33,36,39,41,43,45,47,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64],
[17,3,8,13,18,23,26,29,32,35,38,40,42,44,46,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63],
[18,2,7,12,17,22,25,28,31,34,37,39,41,43,45,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62],
[19,1,6,11,16,21,24,27,30,33,36,38,40,42,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61],
[20,0,5,10,15,20,23,26,29,32,35,37,39,41,43,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60],
[21,-1,4,9,14,19,22,25,28,31,34,36,38,40,42,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59],
[22,-2,3,8,13,18,21,24,27,30,33,35,37,39,41,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58],
[23,-3,2,7,12,17,20,23,26,29,32,34,36,38,40,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57],
[24,-4,1,6,11,16,19,22,25,28,31,33,35,37,39,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56],
[25,-5,0,5,10,15,18,21,24,27,30,32,34,36,38,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55],
[26,-6,-1,4,9,14,17,20,23,26,29,31,33,35,37,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54],
[27,-7,-2,3,8,13,16,19,22,25,28,30,32,34,36,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53],
[28,-8,-3,2,7,12,15,18,21,24,27,29,31,33,35,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52],
[29,-9,-4,1,6,11,14,17,20,23,26,28,30,32,34,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],
[30,-10,-5,0,5,10,13,16,19,22,25,27,29,31,33,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50],
];
let mod = resultSwitchArray[queryResult,0]; //The two inputs should be AttackLevel and DefenseLevel. Column 0 is the AttackLevel 0-30; Row 0 is the DefenseLevel 0-30. So if the Attacker is Level 10 and the Defender Level 5 the result should be 35
let output = `&{template:default} {{name=Demo Output}} {{d100=[[d100 - ${mod}[Mod]]]}}`
let finalRoll = await startRoll(output);
finishRoll(finalRoll.rollId);
};
on('clicked:roll',initiateRoll);
</script>
Scott C. said:
Ah, what you want is custom roll parsing. There are several sheets around using CRP to do similar tasks to what you are looking for. Assuming I've correctly understood what you're looking for, you'll want something like this:
<button type="action" name="act_roll">Roll the d100</button><!-- you can replace the "roll" part of the name with whatever you please. I recommend using dashes in place of spaces (kebob-case) for action buttons.-->
<script type="text/worker">
const extractQueryResult = async function(query){
let queryRoll = await startRoll(`!{{query=[[0[response=?{${query}}]]]}}`);
finishRoll(queryRoll.rollId);
return queryRoll.results.query.expression.replace(/^.+?response=|\]$/g,'');
};
const initiateRoll = async function(event){//Async tag here to allow us to await the various rolls that we're going to do.
let queryResult = await extractQueryResult('Which mod|1|2|3|4|5|6|7|8|9|10');//Await the asynchronous startRoll
const resultSwitchArray = [0,2,6,10,12,16,20,24,30,40,60];//Used an array in place of the switch cause it's a bit more performant. Can easily replace this with your switch statement if you need more complex figuring.
let mod = resultSwitchArray[queryResult];
let output = `&{template:default} {{name=Demo Output}} {{d100=[[d100 - ${mod}[Mod]]]}}`
let finalRoll = await startRoll(output);
finishRoll(finalRoll.rollId);
};
on('clicked:roll',initiateRoll);
</script>