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

Need some help - Use attr outside of repeating section to change attr(s) inside a repeating section

1502605406

Edited 1502731862
I know this has been talked about on here quite a bit before, but I guess I am still not understanding it and I need some help. I am trying to have some attrs outside of a repeating section update the attrs inside of the repeating section. I understand I need to use getSectionIDs and feed the resulting IDs into the names of the repeating sections attrs. I just can't quite figure out how to do this to be used by the setAttrs function. I have been able to narrow it down to the setAttrs function not working. Everything else seems to be ok. Anyone think they can help? FYI: 'repeating_moves_moveattr' is a select field that I am using inside the repeating section to choose a mod value. The mods and 'helpdice' exist outside the section.  on('sheet:opened change:helpdice change:fightmod change:movemod change:talkmod change:searchmod change:weirdmod change:mettlemod',      function(){          console.log('====> change for attributes <====');             getAttrs([           "fightmod",                          "movemod",                          "talkmod",                          "searchmod",                          "weirdmod",                          "mettlemod"                          ], function(values) {                                     var mods = [                             values.fightmod,                             values.movemod,                             values.talkmod,                             values.searchmod,                             values.weirdmod,                             values.mettlemod                             ];                          getSectionIDs('repeating_moves',function(ids){                  _.each(ids,function(id){                      getAttrs([                          "repeating_moves_"+id+"_moveattr",                          "repeating_moves_"+id+"_movemoda",                          "helpdice"                          ], function(values){                             var currentmoveattr =  "repeating_moves_"+id+"_moveattr";                              var currentmovedice =  "repeating_moves_"+id+"_movedice";                             var currentmovemoda =  "repeating_moves_"+id+"_movemoda";                     setAttrs({                         currentmovedice: Math.floor(mods[parseInt(values.currentmoveattr)] + parseInt(values.currentmovemoda) + parseInt(values.helpdice))                     });                                               });                  });              });          });      });  ********** EDIT: To anyone coming here looking how to do this ************ Replace the 3 'setAttrs' lines above with this: let attrs = {}; attrs[currentmovedice] = parseInt(mods[parseInt(values[currentmoveattr])]) + parseInt(values[currentmovemoda]) + parseInt(values.helpdice); setAttrs(attrs); What this does is create a new object array called "attrs". Within that is an object called 'currentmovedice', which we defined earlier by creating the string and using the id from 'getSectionIDs'; and we are pairing that with the new formula. We are then running the function 'setAttrs' on the new object array, which really only includes the one 'currentmovedice' object. The formula is using the "  values[*****]  " format instead of the "  values.**** " format so we can use the other strings we defined earlier using the id from 'getSectionIDs'.
I can get this to work using if/then sheetworkers and drop downs, but that is it.
1502649443

Edited 1502649788
Jakob
Sheet Author
API Scripter
You need to set the repeating_moves_ID_currentmovedice attribute, currently you are setting a (global, non-repeating) currentmovedice attribute. EDIT. Ah, I see the problem. You're trying to do that, but that's not how object literals work. I can give a working answer later when not on my phone. 
1502664352

Edited 1502715688
Jakob
Sheet Author
API Scripter
Do this, instead of the 3 setAttrs lines: let attrs = {}; attrs[currentmovedice] = Math.floor(parseInt(mods[parseInt(values[currentmoveattr])]) + parseInt(values[currentmovemoda]) + parseInt(values.helpdice)); setAttrs(attrs);
1502665886

Edited 1502666226
Hmm, this didn't work. It results in the input field for 'movedice' in each entry of the repeating section turning blank, which I am guessing is a NaN error. It also made a new attribute called 'currentmovedice', which isn't what I was expecting, but if that makes sense than it is fine.
1502719307

Edited 1502722624
chris b.
Pro
Sheet Author
API Scripter
values.helpdice does not exist (not in getAttrs), so it's just erroring out edit: duh i was looking at the first one not second
1502721349
Jakob
Sheet Author
API Scripter
chris b. said: values.helpdice does not exist (not in getAttrs), so it's just erroring out Actually, it's there and should be fine. But other things weren't working, because values.currentmoveattr (=== values["currentmoveattr"]) is not the same as values[currentmoveattr] (===values["repeating_moves_"+id+"_moveattr"]) ( important difference!). I've made some changes to reflect the fact that the formula was also wrong. It should now work and produce a number, under the following conditions: The "repeating_moves_"+id+"_moveattr" attribute is an integer between 0 and 5 (in order to work as array index for the mods array). All of the fightmod, ... mettlemod attributes are also integers. The "repeating_moves_"+id+"_movemoda" attribute is an integer. The "helpdice" attribute is an integer. The Math.floor is unnecessary btw, since all numbers involved are integers. Also, this version should not produce a new currentmovedice attribute; your version, however, would have done that, so maybe you're seeing the results of your previous attempts?
1502723556

Edited 1502731998
That works, and I understand the change you made! Thanks for helping me out and helping me learn something! To anyone looking how to do this: I edited the OP to include the solution.