Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Is there an issue with two setAttrs?

I want a field to be reset to 0 after a button is clicked. Everything works fine until the very end where the input is set to 0 and I was wondering if there is an issue with two setAttrs on("clicked:repeating_spells1:mpcostspellmulti", function(eventInfo) {     let rowId = eventInfo.sourceAttribute.split("_")[2];          let attributes = [         `repeating_spells1_${rowId}_spell_single_mp1`,         `repeating_spells1_${rowId}_spell_multi_target_selected1`,         "mp"     ];     getAttrs(attributes, function(values) {         let mpCost = parseInt(values[`repeating_spells1_${rowId}_spell_single_mp1`]) || 0;         let targetSelect = parseInt(values[`repeating_spells1_${rowId}_spell_multi_target_selected1`]) || 0;         let mpCurrent = parseInt(values.mp) || 0;         let updatedMp = mpCurrent - (mpCost * targetSelect);         setAttrs({             mp: updatedMp,             [`repeating_spells1_${rowId}_checkbox_spell_target_query`]: "0" }, function() {             startRoll(`@{repeating_spells1_${rowId}_roll_spell_single1}`, function(rollResult) {                 finishRoll(rollResult.rollId, {}, function() {                     setAttrs({                         [`repeating_spells1_${rowId}_spell_multi_target_selected1`]: "0"                     });                 });             });         });     }); });
NVM Solved it!
1741080256

Edited 1741080415
GiGs
Pro
Sheet Author
API Scripter
What was your solution? PS: there an be a problem with multiple setAtttrs, but you construction should avoid the common issues.
1741091617

Edited 1741091646
Just moved the startRoll before setAttrs
1741270660
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
It looks like you're trying to determine if the user is selecting multiple targets? For something where you want to do logic based on user input in a roll, I'd recommend using the Async/Await construction and directly querying the user about what roll methods they want to use.
It's actually to calculate how much Mana would be consumed based on the number of targets selected. The value (number of targets) is also shown in the Roll template.