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

API and repeating sections on character sheets

Is it possible via the API to create attributes in repeating sections on character sheets?  I remember doing this in the past, but given that the repeating section attributes have unique IDs as part of the attribute name now is this realistically possible now?
Looking at a simple attribute created as a repeating object: {"name":"repeating_attack_-K9rWJzSqmobyHSFL1de_name", "current":"Quarterstaff","max":"","_id":"-K9rWKdIq0rQVFMWT2Wd", "_type":"attribute", "_characterid":"-K9wHc-GqSXatsmDPf9t"} It seems to me that in order to create an attribute (or most objects) you must specify the _characterid and the name, but there seems to be no way to create a valid name unless I am missing something?  Could you maybe filter the object by names, count them then use the "$#" syntax (e.g. repeating_attack_$1_name in the event that there is only one other existing attack)?
Using the "$#" syntax kind of works... but I will be honest, it's very strange.  In my test I simply added a new attribute name, which is only one attribute of many in the repeating section.  I expected that it would add it to the bottom of the repeating section and the remaining attributes would be blank, however this was not the case.  It added to the "top" of the section and the remaining attributes that I didn't fill in were identical to the row below it. Not sure if there is another way to interact properly with the repeating sections or not...
1456570408

Edited 1456570436
I am curious on this subject too. I used Kryx's import script for home-brew spells on his old shaped sheet and i want it to recreate for new sheet, but i didn't figure out how create new row in repeating section via API.
I am very interested in this as well. Also I would like to add a question to this: How do we get the ID of the row of a button. I would like have a rollbutton in the section and do something like !do --row_id @{row_id
1456586594

Edited 1456586733
Finding the id from already created repeating sections isn't too bad. &nbsp;If you look at the following script, specifically the createRepeating() function along with the individual create"Type"() functions where I pass in the regular expression and naming patter to the function it hopefully should help understand it. &nbsp;If there are questions about it feel free to PM me. <a href="https://app.roll20.net/forum/post/3015847/script-t" rel="nofollow">https://app.roll20.net/forum/post/3015847/script-t</a>... Rereading what you are saying, I might have misunderstood... it sounds like you want something that will auto-populate a row on your sheet through an API call? &nbsp;
1456593046

Edited 1456593303
There are additional problems with creating resources with the API... any of the rows I created through testing, I can't delete them from my sheet. If we can't properly create rows via the API, it seriously limits what is possible as far as interaction with the sheets. &nbsp;Feels like a very serious limitation right now, again unless I am missing something or simply doing something completely wrong. Console.log: DELETE REPEATING ROW: repeating_attack_$4 ERROR: Invalid attempt to delete repeating row: repeating_attack_$4_ CLICKED DELETE REPEATING ROW: repeating_attack_$5 ERROR: Invalid attempt to delete repeating row: repeating_attack_$5_ CLICKED DELETE REPEATING ROW: repeating_attack_$7 ERROR: Invalid attempt to delete repeating row: repeating_attack_$7_ CLICKED
1456766491
chris b.
Pro
Sheet Author
API Scripter
Since there is no create ID in the API, one workaround is you could prepopulate a list of valid IDs in the sheetworker, saving them to a hidden text field with semicolon delimiters. Then to create a row just grab the next one in the list and save it back. On sheet open you could check how many semicolons are in the list and add a few more prepopulated IDs. that is limited and you'd have to open every sheet in your campaign to setup the list of IDs once.
1456768416
The Aaron
Pro
API Scripter
Actually, it appears that getting generateRowID() into the API isn't too difficult. &nbsp;Kevin is testing right now, but here's the code: var generateUUID = (function() { &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; var a = 0, b = []; &nbsp; &nbsp; return function() { &nbsp; &nbsp; &nbsp; &nbsp; var c = (new Date()).getTime() + 0, d = c === a; &nbsp; &nbsp; &nbsp; &nbsp; a = c; &nbsp; &nbsp; &nbsp; &nbsp; for (var e = new Array(8), f = 7; 0 &lt;= f; f--) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e[f] = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(c % 64); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = Math.floor(c / 64); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; c = e.join(""); &nbsp; &nbsp; &nbsp; &nbsp; if (d) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (f = 11; 0 &lt;= f && 63 === b[f]; f--) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b[f] = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b[f]++; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (f = 0; 12 &gt; f; f++) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b[f] = Math.floor(64 * Math.random()); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; for (f = 0; 12 &gt; f; f++){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c += "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(b[f]); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; return c; &nbsp; &nbsp; }; }()), generateRowID = function () { &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; return generateUUID().replace(/_/g, "Z"); };
This actually seems to work. &nbsp;It would be very helpful to have this added to the Wiki, this solves my immediate problem and I will jump over and close the bug ticket I opened.
1456779198
Silvyre
Forum Champion
Kevin said: I will jump over and close the bug ticket I opened. I gotcha. :)
1456823596
Kryx
Pro
Sheet Author
API Scripter
Filip Č. said: I am curious on this subject too. I used Kryx's import script for home-brew spells on his old shaped sheet and i want it to recreate for new sheet, but i didn't figure out how create new row in repeating section via API. This would save me a lot of effort. Can you do the monster import as well? :D It's much simpler than it was before - you just have to put stuff into fields and the sheet will parse it.
1457025547

Edited 1457026611
This method does not check if the ID is existing correct? We would need to use findObj until we don't get an object with that ID if I correctly understood your code. Edit: Hell Yeah. Thank you Aaron for this code. This is so powerful. With the possibility to now store the ID on sheet open in a hidden field and to interacte with repeating sections from the API there really is so much cool stuff I can finally implement in my sheet! Now it is possible to have for example buttons like "Brew Healing Potion" which roll a test and use the rolled values to generate "Healing Potions" and add them to an inventory. This makes me so super happy.
1457029346
The Aaron
Pro
API Scripter
You don't need to worry about duplication of ids. &nbsp;Anything that comes out of that will be unique for the purposes of individual games. &nbsp;You'd need to call the function way more times a second than is possible via the API to have a remote chance of generating a duplicate.
It is unlikely, but possible and finding that error would be pretty annoying I guess :)
1457031786
The Aaron
Pro
API Scripter
Yeah, indeed. &nbsp;also, since RowIDs are treated as case insensitive but are generated from 64 characters with 27 (Z twice) effective duplicates, the chances are slightly higher (~30%), but that's still 130% of a very very very small number. &nbsp;=D
1457041349
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
While it is nice that we have code that can generate unique ID's and can make code that will put the IDs into messages to the API, these are features that ought to be in Roll20! Not in our sheets and APIs!