
<script type='text/worker'>
on('change:repeating_rangedweapons:attr_R_weapon-weight remove:repeating_rangedweapons change:gear_weight change:repeating_gear:gear_weight_r remove:repeating_gear', () => {
getSectionIDs(`repeating_gear`, idArray => {
const fieldnames = [];
idArray.forEach(id => fieldnames.push (`repeating_gear_${id}_gear_weight_r`));
getAttrs(['weight_total', 'gear_weight', ...fieldnames], v => {
const getValue = (id, field) => parseFloat(v[`repeating_gear_${id}_${field}`]) || 0
const total = parseFloat(v.weight_total) || 0
const weight = parseFloat(v.gear_weight) || 0
const weight_r = idArray.reduce((total, id) => total + getValue(id,'gear_weight_r'), 0)
setAttrs({weight_total: weight + weight_r});
});
});
});
</script> So the above code is one of Roll20 API's sheet workers. What I want to do is add repeating_rangedweapons:attr_R_weapon-weight and the item amount (attr_gear_quantity) which is a value from a different fieldset into this sheet worker, but I'm not sure how I can do it with the current written code layout. Essentially I need these red arrow fields to influence the weight calculation so, once triggered by either a change in values or removed entry in the fieldset, it runs again and recalculates weight value. To do this, I must rewrite the code's layout. I cannot use the code as-is because I am attempting to retrieve data for use from multiple fieldsets. Is this even possible? The below was my attempt after trying to rewrite it, but it still doesn't work. I cannot read replies until 8-9 hours from now. <script type='text/worker'>
on('change:repeating_rangedweapons:attr_R_weapon-weight remove:repeating_rangedweapons change:gear_weight change:repeating_gear:gear_weight_r remove:repeating_gear', () => {
getSectionIDs(`repeating_gear`, idArray => {
const fieldnames = []
const total = 0
const weight = 0
const weight_r = 0
idArray.forEach(id => fieldnames.push(`repeating_gear_${id}_gear_weight_r`))
idArray.forEach(id => fieldnames.push(`repeating_rangedweapons_${id}_attr_R_weapon-weight`))
getAttrs(['weight_total', 'gear_weight', ...fieldnames], v => {
const getValue = (id, field) => parseFloat(v[`repeating_gear_${id}_${field}`]) || 0
total += parseFloat(v.weight_total) || 0
weight += parseFloat(v.gear_weight) || 0
weight_r += idArray.reduce((total, id) => total + getValue(id,'gear_weight_r'), 0)
})
getAttrs(['weight_total', 'attr_R_weapon-weight', ...fieldnames], v => {
const getValue = (id, field) => parseFloat(v[`repeating_rangedweapons_${id}_${field}`]) || 0
total += parseFloat(v.weight_total) || 0
weight += parseFloat(v.gear_weight) || 0
weight_r += idArray.reduce((total, id) => total + getValue(id,'attr_R_weapon-weight'), 0)
})
setAttrs({weight_total: weight + weight_r});
})
})
</script>