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

How to find values for repeating section attributes

Hello! I've been all over the forums, the old and new wikis, and tried many, many, things. I cannot seem to get any valid returns on my attempt to pull attributes for repeating sections. I believe this should work: log(  getAttrByName(PCsheets[i].id, "repeating_spells_$1_name") ); But I get this: "ERROR: You tried to use the repeating section row at index 1 for repeating_spells, but there doesn't seem to be a row at that index." "Error: No attribute or sheet field found for character_id -LYUcP0gKHhRg_vWssJw named repeating_spells_$1_name" undefined I've done this with 0,1, and 2 for the "n" value. I am having it attempt for characters I know have spells in their repeating sections, but I'm at a loss. Any suggestions or nudges are most welcome. Thanks!
1583435063
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The index number is a shortcut that you can use when calling a repeating attribute in chat. The actual attribute name is repeating_spells_ID_name where ID is something like -1fgh456-jk890 . The best way to find these from the API is to do a findobjs to get all attributes of a given character and then sort through them to find the repeating attributes you want.
1583457711
The Aaron
Roll20 Production Team
API Scripter
If you need to resolve a repeating row by #, I have an API function that will do it, and an example script: on('ready',function(){ "use strict"; var attrLookup = function(character,name,caseSensitive){ let match=name.match(/^(repeating_.*)_\$(\d+)_.*$/); if(match){ let index=match[2], attrMatcher=new RegExp(`^${name.replace(/_\$\d+_/,'_([-\\da-zA-Z]+)_')}$`,(caseSensitive?'i':'')), createOrderKeys=[], attrs=_.chain(findObjs({type:'attribute', characterid:character.id})) .map((a)=>{ return {attr:a,match:a.get('name').match(attrMatcher)}; }) .filter((o)=>o.match) .each((o)=>createOrderKeys.push(o.match[1])) .reduce((m,o)=>{ m[o.match[1]]=o.attr; return m;},{}) .value(), sortOrderKeys = _.chain( ((findObjs({ type:'attribute', characterid:character.id, name: `_reporder_${match[1]}` })[0]||{get:_.noop}).get('current') || '' ).split(/\s*,\s*/)) .intersection(createOrderKeys) .union(createOrderKeys) .value(); if(index<sortOrderKeys.length && _.has(attrs,sortOrderKeys[index])){ return attrs[sortOrderKeys[index]]; } return; } return findObjs({ type:'attribute', characterid:character.id, name: name})[0]; }; on('chat:message',function(msg){ if('api' === msg.type && msg.content.match(/^!resolve-repeating\b/) ){ let args=_.rest(msg.content.split(/\s+/)), who = getObj('player',msg.playerid).get('displayname'); if(args.length){ _.chain(msg.selected) .map((o)=>getObj('graphic',o._id)) .reject(_.isUndefined) .filter((t)=>t.get('represents').length) .map(t=>{ return {token:t,character:getObj('character',t.get('represents'))};}) .reject(o=>_.isUndefined(o.character)) .map(o=>{ o.attrs=_.reduce(args,(m,a)=>{ let attr=attrLookup(o.character,a,false); m[a]=(attr ? attr.get('name') : '[MISSING]'); return m; },{}); return o; }) .map(o=> `<div><h3>${o.character.get('name')}</h3><ul>${_.map(o.attrs,(a,n)=>`<li><b>${n}</b>-<code>${a}</code></li>`).join('')}</ul></div>`) .tap(out=>{ sendChat('',`/w ${who} ${out.join('')}`); }); } else { sendChat('',`/w ${who} <b>No tokens selected</b>`); } } }); });
Thank you both. That makes sense now. The Wiki (old and new) for API doesn't explain that the number reference is for macro only so I thought it was meant to be part of the getAttrByName method. Aaron, I saw your api during my research. I will take a closer look. Thanks!