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

check attributes in repeating field

I want to create a calculation formula that includes the values ​​of repeated fields,  But New attributes do not appear in the attributes tab. So there is no calculation formula. Is there a way to recognize the repeat command in the sheet and have it calculate it? this is my code, but it is not work. <input type="number" name="attr_lois_now" value="@{lois1_use}+@{lois2_use}+@{lois_repeat_use}" disabled="true"/>
1723823749
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
This looks like an attribute that isn't in the repeating section? If so, there's no way to do this without using sheetworkers (javascript). Note that I HIGHLY recommend changing all attribute calculations to javascript as sheetworkers and autocalcs do not play well together.
1723831003

Edited 1724021683
GiGs
Pro
Sheet Author
API Scripter
Repeating attributes never show up in the attributes tab. We can't offer a solution without knowing the macro you are trying to create, but attribute names for attributes inside a repeating section are long, and include 3 parts: The repeating section name A number or id, for the repeating section row and the attribute yiu have used above: lois_now So a valid repeating section name is something like repeating_something_-52jkeghwi4uyt_lois_now There are ways to create the repeating section name automatically, and to get away without using parts of the above long-winded name, but we can't offer suggestions without knowing more about your situation. Also, I second Scott - moving away from autocalcs (disabled attributes) is a good idea.
1723875939

Edited 1723876009
Thank you for the answer! I'll try to use sheetworkes TT  Scott C. said: This looks like an attribute that isn't in the repeating section? If so, there's no way to do this without using sheetworkers (javascript). Note that I HIGHLY recommend changing all attribute calculations to javascript as sheetworkers and autocalcs do not play well together.
on('change:lois1_use change:lois2_use change:repeating_lois_{id}_use', async eventInfo => { const { newValue } = eventInfo; const nowlois = await getSingleAttrAsync('lois_now'); else if (newValue.includes('1')) { setAttrs({ lois_now: Number(nowlois) - 1 > 0 ? Number(nowlois) - 1 : 0 }); } thank you for the answer!  I tried my best, but I'm not sure if this is the correct code. Can I ask for your help? The lois_use value is a checkbox, in a repeating field. and when it has the value 1, I want to create a script that subtracts 1 from the lois_now value. TT 
1724264004

Edited 1724275869
GiGs
Pro
Sheet Author
API Scripter
you need to use the repeating section name. What is it? Edit: nvm, I see it is called repeating_lois . Why does the name lois popup up in so many attributes?
1724273456

Edited 1724282686
GiGs
Pro
Sheet Author
API Scripter
I'm seeing a few issues with your worker. First, roll20 doesnt support that await/async jeywrods (except in the very specific startRoll usage), so including those will either do nothing or cause the worker to crash - I'm not sure which. Or are you using the plugin that enables them? I don't use that so cant help there. You have this function call: getSingleAttrAsync('lois_now') . I dont see the text of that function, so don't have any idea what it's doing, but if the lois_now attribute is inside your repeating section, it's syntax is incorrect. I generally try to avoid using event.newValue, because there was a bug a while back with the newValue property. I believe its fixed now, but it was around a long time, so I'm wary. Also in your change line you have this: change:repeating_lois_{id}_use That should be change:repeating_lois:use This assumes the repeating section includes an attribute called use , which 'm wondering about since you lois_use in other places. I can tell you how to build that worker without using async or the getSinglettrAsync function. It's a pretty easy function. But I'd need to see the html for your repeating section too.
1724276944
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
In addition to the things GiGs has noted, I saw one other issue. You have a malformed if/else wrapped around your setAttrs. Based on how you have it set up, I don't think you even want an if/else there. Additionally, you don't really need logic in your setAttrs declaration: setAttrs({ lois_now: Math.max(Number(nowlois) - 1, 0)}); Additionally, since you are using the R20async framework. There's some traps that are easy to fall into with it that you should be aware of: It isn't supported by Roll20 and is likely to stop working in the jumpgate update or sometime later as Roll20 updates their backend It makes it easy to get into the habit of grabbing attribute values one at a time. This WILL make your sheet extremely slow though.  Aside from the lack of official support, the other reason I don't use the R20Async framework is that you can get pretty much the same behavior with officially supported code by getting all of the attributes you  might even possibly need in a given event chain all at once. getAttrs and setAttrs take the same time to return whether you are getting one attribute value or 100,000 attributes. In contrast, the time it takes to get/set each attribute individually will increase linearly with the number of attributes you are getting/setting. This then lets you access those values synchronously without needing any special framework.
1724282884
GiGs
Pro
Sheet Author
API Scripter
I thought of using Math.max too, but then noticed it was probably a checkbox with a value of 1, so I'm more included to do this: setAttrs({ lois_now: 1 - Number(nowlois) }); But would need to remove the if statement it is buried inside. I notice it doesn't handle what happens when the checkbox is unchecked.