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

Attribute names being used inside and outside a fieldset

1524380553

Edited 1524383537
vÍnce
Pro
Sheet Author
I messed up and used the same attribute name inside and outside a fieldset. attr_DmgBonus is used inside repeating_weapons and is also used outside the fieldset. Some sheet authors say it shouldn't matter since the attribute within the fieldset would in theory be unique since it resides within the repeating section. And for the most part there doesn't seem to be any issues.  But, I have an example where this is a problem; In this particular case, making a sheet roll from within the repeating section works as expected since it pulls the attribute data directly from within the fieldset.  However, if I make the same sheet roll using an "off-sheet" macro (just calling the repeating sheet roll by it's button name) it appears that it checks and uses the non-repeating attributes first instead of the identically named repeating attribute.  ;-( How can I go about using sheetworkers to fix this?  I have a function that checks the current version of the sheet and can run a "attribute swap" function if the sheet is an older version(pre-swap).  I would like to replace the non-repeating DmgBonus with StrengthDmgBonus.  Any value for DmgBonus should be migrated to StrengthDmgBonus.  After this is done, DmgBonus should be deleted.  Is this possible?  TIA
1524396080
GiGs
Pro
Sheet Author
API Scripter
I am pretty sure attributes can't be deleted with sheet workers, so your best bet is to change both stat names, or to change the one inside the repeating set. Otherwise the problem will continue to happen for people who have characters made from before the change.
1524412042
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, I had the same problem with the HUD. Changed the repeating section attribute name (and the macro references to it obviously).
1524417307
vÍnce
Pro
Sheet Author
I was afraid of that.  ;-( Do these steps sound appropriate? check sheet version and only run my migration function if the sheet is determined to be old save the value of all repeating DmgBonus,  create a new attribute AttackDmgBonus (in sheetworker as well as html) update AttackDmgBonus value with DmgBonus value delete repeating DmgBonus attribute update macro-text used within the repeating section by only replacing @{DmgBonus} with @{AttackDmgBonus} set new version of sheet In step 5, should I not delete DmgBonus (keep as a hidden input) in case people have off-sheet macros that reference it?  Any other suggestions or observations? This is going to really test my limited js skills... Thanks for the help people.
1524418894
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I think 5 is optional
1524419376
vÍnce
Pro
Sheet Author
It's for the AD&D 1e sheet (a close second in popularity to 5e, right? lol).  No one has noticed this quip for nearly 2 years.  But once you see it...
1524436265

Edited 1524436613
vÍnce
Pro
Sheet Author
Using sheetworkers, how might I handle parsing the macro-text attribute below to rename "DmgBonus" to "AttackDmgBonus"?  I would rather not straight out replace the entire old macro-text with a new macro-text value in case someone has customized their macro-text.  Worse case, I suppose we can do a complete swap with the updated macro if I have to.  <textarea name="attr_macro-text">&{template:attacks} {{name=@{character_name}}} {{subtag=@{WeaponName}}} {{attack1=[[1d20 + @{ToHitBonus}[BON] + @{MagicBonus}[MAG] + ?{To Hit Modifier?|0}[MOD]) ]]}} {{damage1vsSM=[[@{DamageSmallMedium} + @{DmgBonus}[BON] + @{MagicBonus}[MAG] + ?{Damage Modifier?|0}[MOD] ]]}} {{damage1vsL=[[@{DamageLarge} + @{DmgBonus}[BON] + @{MagicBonus}[MAG] + ?{Damage Modifier?|0}[MOD] ]]}} {{WeaponNotes=@{WeaponNotes}}} @{whisper_to-hit}</textarea> or, if you can point me to an example... much appreciated.
1524437397

Edited 1524437483
Natha
KS Backer
Sheet Author
API Scripter
Something like that ? (replace ??? by the repeating section name. Warning: not tested and using .map is probably faster than _.each, but less "readable" imho) var update = {}, attrs = []; getSectionIDs("repeating_???", function(idarray) {     _.each(idarray, function(itemid) {         attrs.push("repeating_???_" + itemid + "_macro-text");     });     getAttrs(attrs, function(v) {         _.each(idarray, function(id) {             update["repeating_???_" + id + "_macro-text"] = v["repeating_???_" + id + "_macro-text"].replace("DmgBonus","AttackDmgBonus");         });         setAttrs(update,{silent:true});     }); });
1524438280
vÍnce
Pro
Sheet Author
Cheers Natha.