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

ChatSetAttr in an inline roll in a repeating section

1647890314

Edited 1647900721
Mech
Pro
Sheet Author
I am looking to increment the number of uses of a trait when I roll a special type of roll. The traits are added in repeating sections. To roll this, an inline button within the repating section calculates the roll, and should then add one use to the TraitUses attr. This is all in a custom ccharacter sheet. The button is the one with 'CP'. Here is the code for the button, with the use of the API. <button type='roll' value='&{template:exp}{{name=@{charactername}}}{{roll_name=@{TraitName}}}{{attr=[[1d20 + [[1 + floor(@{TraitUses}/15)]] ]]}} {{combo=[[@{TraitDice} * [[0 + ceil(@{cp}/100)]] ]]}} !modbattr --name @{charactername} --cp|{{cp=CP changes by [[-1]]}} --TraitUses|{{TraitUses=Uses changes by [[1]]}}!!! {{cp=Used}} {{crit=[Critical Hit](~@{charactername}|Crit)}}' name='roll_TraitCheck'> <b>CP</b></button>              Uses:<input type="number" name="attr_TraitUses" value= "0"/>  This is the use of the API. It doesn't read the attr as within the repeating section. TraitUses is the problematic one. !modbattr --name @{charactername} --cp|{{cp=CP changes by [[-1]]}} --TraitUses|{{TraitUses=Uses changes by [[1]]}}!!! But the button itself does, as it uses the following for a simple calculation. {{attr=[[1d20 + [[1 + floor(@{TraitUses}/15)]] ]]}} Here it reads the attr as within the repeating secction and calculates correctly. I cannot use the actual ID of the repeating trait, as it will be different for each one. Is there a way to get the API to read the repeating section attr from within? Edit) What it currently does is add a new general attr called TraitUses and increments that. I have tried many ways but found nothing.
1647954236
timmaugh
Roll20 Production Team
API Scripter
It looks like you're mixing sheet development with api usage, which I think accounts for why the trait resolves on the sheet side, but not on the API side. You could use Fetch to feed that repeating attribute information into the roll correctly. Fetch is a metascript (available in the 1-click) that can "pre-amp" the CSA call. And it can get the rowID or actual repeating attribute from a repeating section based on tests. Something like... *(character name.section.[nameOfSubAttr="Underspackle"].TraitUses.name) That looks on a character named "character name", in a repeating list called "section" for an entry on the list. Every entry on the list has some number of sub-attributes, and the entry we're looking for is where the specific sub-attribute named "nameOfSubAttr" equals "Underspackle". Once we have identified that entry on the list, return the sub-Attribute named "TraitUses"... and SPECIFICALLY, return the name of the attribute. Since it works like a pre-amp to CSA, the Fetch construction processes out to the requested information, and by the time CSA sees the above construction, it will instead read: repeating_section_-M1234567890abcdef_TraitUses And CSA can treat that just like any other attribute for which it is setting a value. If that doesn't make sense, I can try to make it clearer.
1647958213

Edited 1647958260
Mech
Pro
Sheet Author
I didnt really understand, but I was able to solve it. I added a worker script that set a new attr as the row id in a hidden input on the repeating section, and then called that attr on the roll.  Here is the code on the sheet worker:  on("sheet:opened change:repeating_trait", function() {         update_id("trait");     }); var update_id = function(name){ getSectionIDs("repeating_"+name, function(idarray) { for(var i=0; i < idarray.length; i++) { var attrs ={}; attrs['repeating_'+name+'_' + idarray[i] +'_'+name+'Id'] = idarray[i]; setAttrs(attrs); } }); }; Followed by the code on the button: <button type='roll' value='&{template:exp}{{name=@{charactername}}}{{roll_name=@{traitName}}}{{attr=[[1d20 + [[1 + floor(@{traitUses}/15)]] ]]}} {{combo=[[@{traitDice} * [[0 + ceil(@{cp}/100)]] ]]}} !modbattr --name @{charactername} --cp|{{cp=CP changes by [[-1]]}} --repeating_trait_@{traitId}_traitUses|{{traitUses=Uses changes by [[1]]}}!!! {{cp=Used}} {{crit=[Critical Hit](~@{charactername}|Crit)}}' name='roll_traitLevel'> <b>CP</b></button> Uses:<input type="number" name="attr_traitUses" value= "0"/> Basically: repeating_trait_@{traitId}_traitUses Thanks anyways!