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

Repeating Sections and the API. How to pass the row_id of a repeating section to the API.

1460825063
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
First I am going to explain what I am trying to do. Then I am going to list all the problems I have run into trying to do it and ask for advice. Just to be clear, I don't necessarily need to have any one specific problem solved, so much as I need to find a way out of this thicket and get what I am trying to accomplish done.  I would like to be able to press a button within a line inside a repeating section and send the character ID plus the rowID of the repeating section to the API for further processing. I want the API to then be able to use the character ID plus the rowID to look up the the specific information it needs, and process it. I specifically want to send the rowID, because I want the API to be able to write information back to fields within that specific row.  I would have thought that there would be @{row_id} pseudo attribute that would make this information available. Apparently there is not.  See  This suggestion It only has 4 votes and is apparently not on the fast-track.  The link above mentions that it should be possible to work around by simply storing your own copy of the row_id. I would have thought that was simple, but I keep running into the problem of the dubious decision that was made to lowercase everything before passing it back to users, but requiring users to pass it back to the system in the correct case.  Specifically, when I coded an on change event to notice when a field within a repeating section (repeating_skillk_-kfuroxo04waoxv0xexq_skk_name) was changed, parse the eventinfo to find the row_id, then set the row id into repeating_skillk_-kfuroxo04waoxv0xexq_skk_RowID, I ended up with two identical rows. I think that one of them probably has the correct casing of the row ID, but my actually using the lowercased ID caused it to create a 2nd row. I thought I would simply make a call to getSectionIDs and check those against what I parsed out, but that only gives lowercased IDs as well? Why would that give lowercased IDs if actually using lowercased IDs for anything causes a 2nd, duplicate row to be created?!? Does anybody know how to access a row ID that has not been lowercased? Has anybody solved the problem of sending a usable rowID on a macro button? Thanks
1460838278
The Aaron
Pro
API Scripter
In the narrow case where you're just trying to get the Row ID when a button in that row is clicked, what about creating a checkbox that looks like a button, then catching the on('change:attribute',...) for when the checkbox is toggled.  You can then extract the Row ID from it's name and the character id is on the object. From the API, if you know the name pattern of one of the repeating rows, you could look for attributes with that pattern and extract the ids from their names.
1460846315
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I am not just trying to get a row id, I am trying to pass it to the API. My understanding is that a thread worker can't cause a macro to execute nor in any other way kickstart the API. The most it can do is capture some information and store it in a field that a macro button can then send to the API. Specifically I want to pass the API a message that says basically, hey somebody pressed the button on Character X's skill table Row Z. I figure the format might look something like this... value="!edParse~ charID: @{character_id} ~ Skill row: @{RowID}" The problem is saving the information. When I SetAttr() the rowID that I parse out of sheetworkers on change eventInfo it creates a new row, because while I can correct the case of the repeating section and the names, both places I know to get the rowID (eventInfo and GetSectionIDs) does not give the TRUE section IDs, it gives ones that have been vandalized (lowercased) and if I try to use those rowIDs, I end up with a duplicate row.  So yes, I can see how a checkbox could get me a vandalized (lowercased) row ID, but I don't think the sheetworker could kickstart the API.  Am I correct that you are suggesting that if I could get the vandalized row ID to the API, the best thing to do is to call FindObj() looking at all attributes for that character, and testing each one to see if it starts with repeating_skills and ends with SKK_Name, and where the middle, if lowercased looks like the rowID sheetworkders found? I suppose that would probably work, but it seems like a hugely wasteful way of doing things. 
1460853315
The Aaron
Pro
API Scripter
Any change that a Sheet Worker makes to an attribute (or that a user makes to an attribute, such as by checking/unchecking a checkbox that looks like a button) becomes an event on the API side.  With that "Button" checkbox in the row, when you get the change event, you will know precisely which row it occurred in.  In that way, the Sheet Workers can activate API functionality, they just can't execute API chat commands.  The bigger problem is going the other direction.  There isn't anything the API can do that will cause a Sheet Worker to activate.
1460893594
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Oh, OK, that makes sense now. For some reason I had totally forgotten that the API could get events like add attribute and change attribute.  So I simply have the API look for Change Attribute instead of sheet workers, see if attribute name ends is SKK_Roll, if not, ignore the event, if it does parse the name to get the rowID and process it. Makes all sorts of sense now, thanks! I don't suppose you can point me to some css that makes a checkbox look like a button?    I never needed to do that before. 
1460900035
The Aaron
Pro
API Scripter
Sure! &nbsp;This one looks pretty straight forward:&nbsp; <a href="http://jsfiddle.net/zAFND/2/" rel="nofollow">http://jsfiddle.net/zAFND/2/</a> In your case, you won't need the :checked style that turns it red, but the rest should be enough to get you started!
1460920670
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Thanks!
1461600600

Edited 1461600880
I think I do exactly what you want to do by simply adding a hidden attribute _id to the row and adding a SheetWorker which listens to all the fields and open. It then sets the id to this attribute. This allows you to have a roll syntax like !edParse~ charID: @{character_id} ~ Skill row: @{RowID}" For example &lt;fieldset class="repeating_spellcasting"&gt; &lt;input &nbsp;class="hidden" type="text" name="attr_spellcasting_id" value=""&gt;&lt;/input&gt; &lt;button class="buttoninput buttoninput-center" type='roll' name='roll_spellcasting_basis' value='!shadowrun --id @{spellcasting_id}'&gt;&lt;/button&gt; ... &lt;/fieldset&gt; on("sheet:opened change:repeating_spellcasting", function() {update_id("spellcasting");}); var update_id = function(name){getSectionIDs("repeating_"+name, function(idarray) {for(var i=0; i &lt; idarray.length; i++) {var attrs ={};attrs['repeating_'+name+'_' + idarray[i] + '_'+name+'_id'] = idarray[i];setAttrs(attrs,{silent:true});}});}; This sets ALL id fields in the repeating section. Be careful with the attribute name in the example, I use a pretty weird syntax and had never time to cleanup the second +name.