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 accessing / creating repeating_sections attributes

I am trying to lookup / create a&nbsp; repeating_savemod_ .&nbsp; According to&nbsp; <a href="https://wiki.roll20.net/API:Objects" rel="nofollow">https://wiki.roll20.net/API:Objects</a> &nbsp;- I should be able to use&nbsp; repeating_savemod_$0_global_save_name &nbsp;in findObjs and&nbsp; createObj However when I look up&nbsp; repeating_savemod_$0_global_save_name &nbsp;I get nothing, but when I look up attributes starting with&nbsp; repeating_savemod_ &nbsp; I see the attributes I am expecting Code: let char_id = "-Lja7EH4XMPypemsfO7b" let attr = findObjs({ type : 'attribute' , characterid : char_id , name : "repeating_savemod_$0_global_save_name" , } , { caseInsensitive : true })[ 0 ] log( "repeating_savemod_$0_global_save_name" + " =&gt; " + JSON . stringify (attr)) findObjs({ _type : 'attribute' , _characterid : char_id}). forEach ((t) =&gt; { let name = t. get ( "name" ) if (name. startsWith ( "repeating_savemod_" )) log(name + " =&gt; " + JSON . stringify (t)) }) ; Result: "repeating_savemod_$0_global_save_name =&gt; undefined" "repeating_savemod_-Lq2RmvjiCI3kixkEAa5_global_save_roll =&gt; {\"name\":\"repeating_savemod_-Lq2RmvjiCI3kixkEAa5_global_save_roll\",\"current\":\"1d4\",\"max\":\"\",\"_id\":\"-Lq2Rmvo7iR5hEZFCv4Q\",\"_type\":\"attribute\",\"_characterid\":\"-Lja7EH4XMPypemsfO7b\"}" "repeating_savemod_-Lq2RmvjiCI3kixkEAa5_global_save_name =&gt; {\"name\":\"repeating_savemod_-Lq2RmvjiCI3kixkEAa5_global_save_name\",\"current\":\"Bless\",\"max\":\"\",\"_id\":\"-Lq2Rmvu0YRa4trDXOIw\",\"_type\":\"attribute\",\"_characterid\":\"-Lja7EH4XMPypemsfO7b\"}" "repeating_savemod_-Lq2RmvjiCI3kixkEAa5_global_save_active_flag =&gt; {\"name\":\"repeating_savemod_-Lq2RmvjiCI3kixkEAa5_global_save_active_flag\",\"current\":\"0\",\"max\":\"\",\"_id\":\"-Lq2Rmvy7WQS1f0rRbsb\",\"_type\":\"attribute\",\"_characterid\":\"-Lja7EH4XMPypemsfO7b\"}" "repeating_savemod_-Lq2RmvjiCI3kixkEAa5_options-flag =&gt; {\"name\":\"repeating_savemod_-Lq2RmvjiCI3kixkEAa5_options-flag\",\"current\":\"0\",\"max\":\"\",\"_id\":\"-Lq2RqUgeyV8vcnyVuRI\",\"_type\":\"attribute\",\"_characterid\":\"-Lja7EH4XMPypemsfO7b\"}" Can someone spot what I am doing wrong.
OK - further testing tells me that&nbsp; getAttrByName &nbsp;does work with $0. That solves 1/2 the problem. I can work with&nbsp; getAttrByName. However I need to understand how to create a new repeating section.
1604855364
The Aaron
Roll20 Production Team
API Scripter
You simply create an attribute with the correct format of name. The tricky but is creating a rowid. I have a function around that does it the way Roll20 does, I'll dig that up when I'm back at my computer.&nbsp;
1604855776

Edited 1616675474
timmaugh
Pro
API Scripter
Yeah, you have to use the actual name with the getAttrByName() function. But as far as creating a new repeating section.. are you talking about wanting to add a new entry to an existing repeating section, or add a completely new repeating section to a character sheet? And, if it's the latter, you need to do this from the API rather than within the sheet design, itself? Just want to make sure what you're looking for. If you have any question about what a character has in terms of repeating sections, I'd suggest my XRay script (part of the InsertArg script). (Although InsertArg has a fairly steep learning curve, XRay is quite straightforward.) That script would also help with knowing what associated sub-attributes each section might have if what you wanted to do was add a new item to a repeating list. If you want to add a completely new repeating section, it seems you'd have to go about it as follows (I've never done it, so there's a good chance someone more knowledgeable will come along and give a warning about some step along the way being problematic or prohibited... but until then...): 1) determine name for repeating section (ie, "pancakes" from "repeating_pancakes"); this can't have an underscore 2) determine the various sub-attributes that you'll need, be ready with a name pattern for each (ie, "pancake_name" from "repeating_pancakes_UUID_pancake_name"); this one can have underscores 3) When you're ready to add an element to the repeating section, derive a UUID for the entry that will be shared across all sub-attributes; as I understand it, this can be anything, but the code that is actually used by Roll20 for object creation behind the scenes is something like: const generateUUID = (() =&gt; { &nbsp; &nbsp; let a = 0; &nbsp; &nbsp; let b = []; &nbsp; &nbsp; return () =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; let c = (new Date()).getTime() + 0; &nbsp; &nbsp; &nbsp; &nbsp; let f = 7; &nbsp; &nbsp; &nbsp; &nbsp; let e = new Array(8); &nbsp; &nbsp; &nbsp; &nbsp; let d = c === a; &nbsp; &nbsp; &nbsp; &nbsp; a = c; &nbsp; &nbsp; &nbsp; &nbsp; for (; 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 &amp;&amp; 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; }; })(); const generateRowID = () =&gt; generateUUID().replace(/_/g, "Z"); (code courtesy (or at least via) The Aaron) 4) Use that in your naming pattern for the associated attributes, using createObj()... that function will coerce R20 into creating the individual UUIDs for the individual attributes, but you'll be naming them using the UUID you derived. Make sure to supply all of the information createObj() might require (current, max, etc.). Does that show on a character sheet? Are there javascript types that have to be considered when you create these? I can't answer those questions as I haven't gone down this particular road myself, but the above is at least how I would start. Post back with problems you encounter. I'm interested to see this, myself. EDIT: Included the last line of the code (the generateRowID function). That is necessary specifically in this usage (row ID creation) to keep underscores from cropping up in the UUID generated. Since the underscores serve as boundaries for the various parts of the repeating element's name, you can't have extra ones popping up in the rowID portion.
1604855950
timmaugh
Pro
API Scripter
The Aaron said: You simply create an attribute with the correct format of name. The tricky but is creating a rowid. I have a function around that does it the way Roll20 does, I'll dig that up when I'm back at my computer.&nbsp; Ahh-ha! I think I might have helped with this. Such are the pains of beginning a post, getting interrupted by small bipedals, and then completing the post only to see that the guy I was cribbing had already chimed in. =D
1604862877
The Aaron
Roll20 Production Team
API Scripter
Excellent. Less for me to do. =D
Thanks guys - now able to set the&nbsp;global_attack_active_flag as well as the global_save_name and&nbsp;global_save_roll. It updates on the character sheet but does not seem to effect the roll. So I add bless but it does not roll an extra d4. Flipping the flag off then on makes it work. Is there anything else I need to to to get the OGL 5e saving throws to pick up the changes
OK - looks like I need to reconstruct global_save_mod and&nbsp; global_save_mod_flag Will get back if I get things working&nbsp;