
I'm working on the character sheet for Infinity 2d20, which has a rolling system that's a bit complex to implement in Roll20: each d20 which rolls under a target number is 1 success. If a d20 rolls under the character's Focus in a given skill, that counts as 2 successes. In the past I used a very complex inline roll string for this, but that is unmaintainable; I have no idea how I got it to work in the first place. I've managed refactor the rolling system using Custom Roll Parsing, but now I'm faced with the annoying task of including an individual worker script for each attribute that can be rolled against. This is doable with some external scripting to generate the HTML and Javascript, but I can't help wondering if there is an easier way to do this. Here's what I use right now for each attribute/skill: <!-- HTML -->
<button type="roll" name="roll_SKILLNAME" value="@{SKILLNAME_action}"></button>
<button type="action" name="act_SKILLNAME-action" class="hidden"></button>
<input type="hidden" name="attr_SKILLNAME_action" value="">
// Scripts
on("clicked:SKILLNAME-action", (info) => { // Include one version of this script for every skill/attribute on the sheet.
startRoll("&{template:skillroll} {{target_number=[[?{Attribute|Agility,@{agility}|Awareness,@{awareness}|Brawn,@{brawn}|Coordination,@{coordination}|Intelligence,@{intelligence}|Personality,@{personality}|Willpower,@{willpower}}[Attribute]+@{skill_SKILLNAME_exp}[Skill EXP]]]}} {{roll=[[?{Number of dice|2}d20cf>[[21-?{Complication Range|1}]]cs<[[@{skill_SKILLNAME_foc}]]]]}} {{header=SKILLNAME Check}} {{subheader=@{character_name}, Difficulty ?{Difficulty|1}}} {{skill_foc=[[@{skill_SKILLNAME_foc}]]}}", (allRolls) => {
const computed = calcSkillRoll( // Counts the number of successes in roll.
allRolls.results.roll.dice,
allRolls.results.target_number.result,
allRolls.results.skill_foc.result
).successes;
const computedResults = {
roll: computed
};
finishRoll(
allRolls.rollId,
computedResults
);
});
}); There's a couple of helper scripts with this, but these two sections have to be included for each rollable attribute. This is not only a pain to maintain, but it's a massive number of lines that just feel wasted. I had the idea of instead using a generic function that has the relevant attributes passed to it. In concept, it would look something like this: <!-- HTML -->
<button type="roll" name="roll_SKILLNAME" value="@{SKILLNAME_action}"></button>
<button type="action" name="act_generic-roll-action" class="hidden" value="SKILLNAME,ATTRIBUTENAME" ></button>
<input type="hidden" name="attr_SKILLNAME_action" value="">
// Scripts
on("clicked:generic-roll-action", (info) => { // Just one of these is necessary.
const rollString = generateRollString(info.value.SKILLNAME, info.value.ATTRIBUTENAME); // Helper function that would replace the necessary sections in the generic roll to create the actual inline roll string.
startRoll(rollString, (allRolls) => {
const computed = calcSkillRoll( // Counts the number of successes in roll.
allRolls.results.roll.dice,
allRolls.results.target_number.result,
allRolls.results.skill_foc.result
).successes;
const computedResults = {
roll: computed
};
finishRoll(
allRolls.rollId,
computedResults
);
});
}); I actually got this working with jQuery! To my dismay though, it seems that jQuery isn't yet on the main servers. I then thought that I could use the HTMLAttributes from the action button eventInfo as parameters, but this doesn't work since the method I'm using doesn't pass any information about the HTML action button to the script. The only info that is passed is the name tag, which I can't really use as a parameter since that's what calls the script. Is there some other method I'm missing that would let me pass parameters to a sheet worker?