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 .
×

Help With Repeating Sections

1581845330

Edited 1581845400
I've been getting back into the swing of jscript since I took it for about 2-3ish years during high school (which was about 6 years ago granted) but I am lost on so much when it comes to repeating sections and how they work within roll20. I got the hang of the ID and separated attribute names for calling certain bits as needed and for the most part I've gotten that part of this API to work. It's serving well as a way to relearn jscript as well but one thing I can't seem to get to work in any capacity is _reporder_repeating_<sectionname> and some aspects regarding it. on("change:_reporder:repeating_weapons", function(eventInfo) { getSectionIDsOrdered("repeating_weapons", function(idarray) { ID = idarray[0]; getAttrs(["_reporder_repeating_weapons", "EquippedName", "repeating_weapons"+ID+"_WName"], function(v) { setAttrs({ EquippedName: v["repeating_weapons"+ID+"_WName"] }); }); }); }); Some searching around and attempting to figure out how to get it so that when the order of the repeating_weapons section is changed by moving stuff around it'll automatically change a readonly input field I have to match the name of it elsewhere on the sheet. I did find this but I'm not sure I quite understand what its even doing. var getSectionIDsOrdered = function (sectionName, callback) { 'use strict'; getAttrs([`_reporder_${sectionName}`], function (v) { getSectionIDs(sectionName, function (idArray) { let reporderArray = v[`_reporder_${sectionName}`] ? v[`_reporder_${sectionName}`].toLowerCase().split(',') : [], ids = [...new Set(reporderArray.filter(x => idArray.includes(x)).concat(idArray))]; callback(ids); }); }); }; Other aspects of the repeating section works, if I were to instead change it to change:repeating_weapons with the same code shown in the topmost code snip it updates the name of the EquippedName attribute just fine. As a work-around I also tried to do it with a button, setting it up near but not inside of the repeating_weapons fieldset. Even using clicked:equip  which was the name of it, act_equip it didn't actually do anything. It seemed like the action part of the button just failed overall. Looking through the wiki it even tells me to use this as a basis but it's gotten me nowhere. on ( "change:_reporder:<sectionname>" , function (eventInfo) { // Where <sectionname> above should be a repeating section name, such as skills or spells }); Any help would be greatly appreciated.
1581856467

Edited 1581856555
GiGs
Pro
Sheet Author
API Scripter
I've never used that function, so not quite sure, but I notice the wiki is pretty inconsisitent about whether you need to use repeating_ or not. IME you should always use it. This is the change function on the wiki: on ( "change:_reporder_repeating_<sectionname>" , function (eventInfo) { // Where <sectionname> above should be a repeating section name, such as skills or spells }); notice the repeating_ part. It also has the function created by Jakob two years ago, but it has changed. The version on the wiki (notice the lack of "repeating""): var getSectionIDsOrdered = function (sectionName, callback) { 'use strict' ; getAttrs ([`_reporder_${sectionName}`], function (v) { getSectionIDs (sectionName, function (idArray) { let reporderArray = v[`_reporder_${sectionName}`] ? v[`_reporder_${sectionName}`]. toLowerCase (). split ( ',' ) : [], ids = [... new Set(reporderArray.filter(x => idArray.includes(x)).concat (idArray))]; callback (ids); }); }); }; The version created by Jakob on this thread : var getSectionIDsOrdered = function (sectionName, callback) {   'use strict';   getAttrs([`_reporder_repeating_${sectionName}`], function (values) {     getSectionIDs(`repeating_${sectionName}`, function (idArray) {       let reporder = values[`_reporder_repeating_${sectionName}`],         reporderArray = reporder ? reporder.toLowerCase().split(',') : [],         ids = [...new Set(reporderArray.filter(x => idArray.has(x)).concat(idArray))];       callback(ids);     });   }); }; Since the wiki is updated by users more often than devs, it's hard to know which version is correct without testing. It looks like idArray.has should be idArray.includes, but the other changes ("repeating_" ) might also be needed. Also Chris D. provides an alternate version of the script in the above linked thread. But that version also misses out the "repeating_" text so maybe it isnt needed.
Well through some testing I can confidently say that the version put forth by Chris D. is the one that does function in the sense it lets me call for the parts of a weapon with the ID generated by repeating weapons and sort. Which was the one I was using from the start since it was on the wiki, I'm still trying to figure out how to have an input field when things in the repeating section are reordered but I believe I've exhausted every possible combination and adjustment to the code I could have used without redoing it from scratch.
1581880762

Edited 1581880775
GiGs
Pro
Sheet Author
API Scripter
What is the purpose of the input field? You can call the first item in a repeating section with @{repeating_section_$0_attribute_name}, and $1 for the second, $2 for the third, etc. Does that not suffice?