Hi all, I have a sheet worker that I want to run when an attribute is updated and when the sheet is opened, but it's only running when the attribute is updated. I've also tried setting it up to run when a "refresh" button is clicked, and that's not working either. The purpose of the worker is to take blocks of text describing the effects of powers, and modify them for alternate modes: one mode removes the brackets around inline rolls so that it doesn't roll anything; the other three modify the inline rolls so that it rolls multiple times and takes the best/worst/middle result, respectively. As mentioned, the script works as desired, it just doesn't trigger all of the times that I want it to. Worker Code: const groups = ['basic', 'lesser', 'greater', 'feature', 'item', 'other'];
groups.forEach(function (group) {
const texts = ['attack_hit_', 'attack_crit_', 'attack_miss_', 'attack_effect_', 'attack_maintain_', 'attack_special_'];
texts.forEach(function (text) {
on("change:repeating_" + group + ":" + text + group + " clicked:refresh sheet:opened", function() {
usText = "repeating_" + group + "_" + text + group
getAttrs([usText], function (values) {
var fStr = values[usText] + " ";
var dfStr = values[usText];
var fdfStr = values[usText];
let uniqueRolls = values[usText].match(/(?<=\[\[).*?(?=\]\])/g).filter(function (value, index, self) {
return self.indexOf(value) === index; });
uniqueRolls.forEach(function(roll, index) {
let rollMatch = "[[" + roll + "]]";
let fRoll = "[[{" + roll + "," + roll + "}d1]]";
let dfRoll = "[[{" + roll + "," + roll + "}dh1]]";
let fdfRoll = "[[{" + roll + "," + roll + "," + roll + "}kl2dl1]]";
fStr = fStr.replace(rollMatch, fRoll);
dfStr = dfStr.replace(rollMatch, dfRoll);
fdfStr = fdfStr.replace(rollMatch, fdfRoll);
});
setAttrs({
[usText + '_noroll']: values[usText].split("[[").join("").split("]]").join("") + " ",
[usText + '_f']: fStr + " ",
[usText + '_df']: dfStr + " ",
[usText + '_fdf']: fdfStr + " "
});
});
});
});
}); Button Code: <button type="action" name="act_refresh"></button>