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 .
×
If you're having issues creating a character, clear your cookies and log in again. If you continue having issues, contact us.
Create a free account

Sheetworker: Settings defaults for new repeating row

1684309200

Edited 1684309218
vÍnce
Pro
Sheet Author
Does this look OK?  I only want to set default values for a new repeating_weapon row when created by a player. TIA // Set repeating_weapon defaults for new weapon row // beneficial for API access to the repeating attributes on('change:repeating_weapon:weapon_name', (eventInfo) => { clog(`Change Detected:${eventInfo.sourceAttribute}`); const output = {}; // test if API is creating the repeating row and bail if (eventInfo.sourceType !== 'player') { return; } // testing for new weapon_name (ie no existing value) else if (eventInfo.newValue === eventInfo.previousValue) { output.repeating_weapon_weapon_attack_type = 0; // add additional attributes... setAttrs(output, { silent: true, }); } });
1684316812
GiGs
Pro
Sheet Author
API Scripter
Is there a reason you cant just enter value="0" in the html for the repeating_weapon_weapon_attack_type element? Does that not work? I'd remove the else from this part else if (eventInfo.newValue === eventInfo.previousValue) I'm normally encouraging people to add else conditions, but since the previous test contains a return statement, it doesnt really do anything. Also, this part if (eventInfo.newValue === eventInfo.previousValue) { There's a bug in roll20 where newly created elements have the same newValue and previousValue. Are you deliberately taking advantage of that there?
1684329393
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep Vince, that looks good to me. Gigs, the reason to do this is if you've previously had a different default value in the html, you don't want to just update the html value because then rows that were already created and never had that input changed will be set to the new default. It's something that has caused upgrade pains in several sheets. It's not quite a bug, but it's a not immediately obvious side effect of the relationship between the A&A tab and html default values.
1684332340

Edited 1684332475
vÍnce
Pro
Sheet Author
For some reason an API script doesn't seem to detect the defaults in HTML (I also set them in the HTML), so I have found it necessary to set these defaults in the sheetworker to help with API detection of these attributes.
1684332796

Edited 1684332940
vÍnce
Pro
Sheet Author
I'm just trying to prevent an accidental overwrite/reset of an existing repeating row's attributes...  one person has found that that has happened on some of their existing weapons/attacks and so I added the else if to just be stricter with it. But it makes sense that it actually isn't doing anything beyond two if statements in this case because of the return in the first if statement. Is there something else I can do to only set defaults on a brand new repeating row?
1684339054
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
vÍnce said: For some reason an API script doesn't seem to detect the defaults in HTML (I also set them in the HTML), so I have found it necessary to set these defaults in the sheetworker to help with API detection of these attributes. Yep, API scripts using the .get syntax won't see default values. Setting them via sheetworker is about the only way to guarantee an API script will see them.
1684359040
vÍnce
Pro
Sheet Author
@Scott, I think I had a similar conversation with you about this exact subject before... ;-) To anyone; 1. Would it be possible for an API mod to trigger my event process above and trigger an existing row's attributes to be overwritten with defaults?  Or even a player for that matter? 2. Is there some additional method(s) I can add to ensure that attribute defaults are only written to the sheet when a new weapon row is added?  3. Or is my method sufficient? TIA
1684371346
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I think we did! I also think what you've got should be perfectly adequate.
1684375519
vÍnce
Pro
Sheet Author
As always, thank you for being awesome Scott and GiGs!