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

Adding Repeating Attributes to Character Sheet Via API Not Working

When I run my script that automatically adds repeating attributes, such as weapons and spells, to a Savage Worlds Tabbed character sheet, they aren't showing up. The first weapon config is expanded and that's it. I've had this issue before recently. 
1591912999
GiGs
Pro
Sheet Author
API Scripter
What code are you using to add the repeating attributes?
1591918531

Edited 1591918705
In total it's far more code than easily postable. Here is a snippet. That has already been working for a while now. A couple weekends ago it stopped working just like it is now, then started working the next morning. Old versions of the script don't help. Nothing repeating works. It just opens the config of the first item. This code has been used successfully many times over. It works. I also have excellent error logging. No errors are being thrown. "setAttribute" :   function ( characterId ,  attributeName ,  current ,  max ) {          if  (! characterId  ||  typeof   characterId  !==  'string' ) {              throw   new   Error ( "Invalid parameter 'characterId'" );         }          if  (! attributeName  ||  typeof   attributeName  !==  'string' ) {              throw   new   Error ( "Invalid parameter 'powerName'" );         }          if  ( typeof   current  !==  'string'  &&  typeof   current  !==  'number' ) {              throw   new   Error ( "Invalid parameter 'current'" );         }          if  ( typeof   max  !==  'undefined'  &&  typeof   max  !==  'string'  &&  typeof   max  !==  'number' ) {              throw   new   Error ( "Invalid parameter 'max'" );         }          if  (! current )  current  =  "" ;          if  (! max )  max  =  "" ;          var   attribute  =  this . getAttribute ( characterId ,  attributeName );          if  ( attribute ) {              attribute . set ( "current" ,  current );              attribute . set ( "max" ,  max );         }  else  {              createObj ( "attribute" , {                  "name" :   attributeName ,                  "current" :   current ,                  "max" :   max ,                  "characterid" :   characterId             });         }     },
1591919163

Edited 1591919213
GiGs
Pro
Sheet Author
API Scripter
If its not working now, something's up. But with roll20 as it is right now, have you confirmed that the problem is in the script? We are plagued with intermittent sandbox slowdowns and crashes. When the script stops working. is it just the repeating section code that fails? Do other script functions still work, or other scripts keep working? The bits to really examine arent shown there. The getAttribute function seems important, as well as whatever routine defines attributeName . If a script is too big to post in the forums, like this case, you can post it online, on pastebin or gist.github.com for example. You dont need to put quotes around "setAttribute" at the start by the way.
1591919596

Edited 1591919801
One thing I haven't been able to figure out is how the author of the character sheet is generating the unique id that goes in the middle of the repeating attribute name, so I made my own functions for that. The id the character sheet generates looks random, but it not, because I found it is what the repeated items sort by. It occurs to me as I write this that the character sheet code is on GitHub and I can read it to find out the answer. I made these and they both work, but I'm going to read the source code in GitHub and find out.      "createUniqueIdByDateTime" :   function ( attributePrefix ) {          if  (! attributePrefix  ||  typeof   attributePrefix  !==  'string' ) {              throw   new   Error ( "Invalid parameter 'attributePrefix'" );         }          const   uniqueId  =  attributePrefix  +  "000"  +  new   Date (). getTime (). toString ();          return   uniqueId ;     },      "createUniqueId" :   function ( attributePrefix ,  powerName ) {          if  (! attributePrefix  ||  typeof   attributePrefix  !==  'string' ) {              throw   new   Error ( "Invalid parameter 'attributePrefix'" );         }                   if  (! powerName  ||  typeof   powerName  !==  'string' ) {              throw   new   Error ( "Invalid parameter 'powerName'" );         }          let   trimmedPowerName  =  powerName . replace ( / [^ A-Za-z0-9 ] / gm ,  "" );          let   newId  =  attributePrefix  +  trimmedPowerName ;          let   neededCharLength  =  20  -  newId . length ;          if  ( neededCharLength  >  0 ) {              const   chars  =  '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ;              for  ( var   i  =  neededCharLength ;  i  >  0 ; -- i ) {                  newId  +=  chars [ Math . floor ( Math . random () *  chars . length )];             }                              uniqueId  =  newId ;         }  else  {              uniqueId  =  newId . substr ( 0 ,  20 );         }          return   uniqueId ;     },    
1591919958
GiGs
Pro
Sheet Author
API Scripter
Thats probably your issue. There is a way to generate correct UUIDs that roll20 will accept. Use this function by Aaron: <a href="https://app.roll20.net/forum/post/3025111/api-and-repeating-sections-on-character-sheets/?pageforid=3037403#post-3037403" rel="nofollow">https://app.roll20.net/forum/post/3025111/api-and-repeating-sections-on-character-sheets/?pageforid=3037403#post-3037403</a> There's likely a version of this function in the chatSetAttr script too, if you want to check =if there are variant versions.
I'll use that, but my way has been working for weeks. It has worked perfectly for many weeks as I refine my scripts.
1591920368
GiGs
Pro
Sheet Author
API Scripter
Roll20 will accept a lot of random generated UUIDs, but if you dont follow the building rules in that function, eventually you'll hit an incompatible one. Since a lot will work, it can take a lot of use before you hit an error.&nbsp; I cant say definitively this is the issue you're running into, but it's worth replacing the code to eliminate one source of failure.
You fixed it. You 100% fixed it. Wow. Something about my time based uniqueId generation must not work at certain times.Weird, but you totally fixed it. Thank you so much!!!
1591926413
GiGs
Pro
Sheet Author
API Scripter
Yay! You're welcome (but Aaron deserves the credit for discovering this years ago) :)
1591932904
The Aaron
Roll20 Production Team
API Scripter
I just extracted the code from the Roll20 website. =D&nbsp; However, using that code will generate unique ids identical to Roll20s, which means that they will pass whatever validation rules are in place.&nbsp; As an added benefit, you can reverse engineer the time that the id was generated, which can be fun.&nbsp; =D