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 here.
×
×
Cookie Preferences
We use Cookies to help personalize and improve Roll20. For more information on our use of non-essential Cookies, visit our Privacy Policy here.
Is it possible to get section Id of the repeating section that called a sheet worker. The only way I have found to do this is to add a hidden attribute inside the fieldset and fill it when the row is created. I hope that makes sense.
Walt S said: Is it possible to get section Id of the repeating section that called a sheet worker. The only way I have found to do this is to add a hidden attribute inside the fieldset and fill it when the row is created. I hope that makes sense. You can use a regular expression to extract the id from the sourceAttribute property of the eventInfo object.
Walt S said: Like this on("change:repeating_melee:primWpnSkill", function(eventInfo) { let RID = eventInfo.sourceAttribute.slice(18,38); Right, that's even simpler than a regular expression :)
Jakob said: Walt S said: Like this on("change:repeating_melee:primWpnSkill", function(eventInfo) { let RID = eventInfo.sourceAttribute.slice(18,38); Right, that's even simpler than a regular expression :) But it would only work for that specific repeating section, so for other repeating sections, the slice would have to change.
It will have to work with more than one section so I will have to go delve into regular expressions, thanks Jakob and Finderski for getting me on the right path.
Here's a website I found that's been helping me figure out regular expressions (because I'm having to learn them, too): <a href="https://www.regextester.com/?fam=102769" rel="nofollow">https://www.regextester.com/?fam=102769</a> You could paste in several things with row IDs and you'd be able to see if it's finding the correct stuff no matter what the string is.
on("change:repeating_melee:primWpnSkill", function(eventInfo) { let sourceA = eventInfo.sourceAttribute let regex = /[^_]*_[^_]*_[^_]*/g; let row = sourceA.match(regex); That was not fun.
Ah, I'm sorry I didn't see this earlier, I actually have a function already to do this in an API script I'm writing. The split() function can also be used to get the rowid and attribute name. var attrinfo = {};
attrinfo.ownerid = obj.get("_characterid");
var name_arr = obj.get("name").split("_");
attrinfo.rowid = name_arr[2];
attrinfo.name = name_arr[3];
attrinfo.current = obj.get("current");
return attrinfo;
Of course, in a Sheet Worker you'd use eventInfo.sourceAttribute to get the full name instead of obj.get("name")