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 .
×
D&D 2024 has arrived! Pre-order the new core rulebooks now and get an exclusive pre-order bonus for free!
Create a free account

[Request] Repeating Sections to Chat

I don't know what I'm doing, or even if this is the right place to post. I'm a noob and don't know where to look to educate myself in a timely fashion.  I've spent a week on this fighting the script and just need to trash it and start from scratch and this is all like black magic to me. I have a bunch of repeating sections on my character sheets I want to output to chat.   Example: Character Sheet Contains    'HighConcept' //attr not a repeating item    'Trouble' //attr not a repeating item    'Aspect' //From Repeating Section    ...    'Aspect' //From Repeating Section 'User Updates Aspects' , 'Store  $AllAspects ' 'User pushes a button on character sheet to display all Aspects to Chat' Output (something like a power card?): "The Aspects are: '$HighConcept', '$Trouble', '$Aspect', ... , '$Aspect' " I need to iterate through the list of the repeating items and display the output when the button is pressed. On a change to the repeating elements.  Instantiate a string.  Iterate the elements of the repeating section, append each element to the string.  Set an attribute $AllAspects with the value of the string.  A button is then set up to reference the attribute $AllAspects and output it's contents to chat. I'm assuming I need to use a sheetworker to accomplish this, but the sheetworker entry in the wiki doesn't do much hand-holding on this.  I'm sure if someone showed me the recipe I could tweak it to do anything else I needed to, but I'm just not able to grok this.
1478879600

Edited 1478879653
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
While I don't know how this would be done (I have zero experience making character sheets), I would imagine that you could look at the code in either the 5e Shaped sheet or the Pathfinder sheet on  github . They both have books that are created (I assume by sheetworkers) that output a command button menu of all the available attacks or spells (shaped I believe only does spells) to chat. I would think that the basic sheetworker to do this would be the same for your instance, you just wouldn't be making chat command buttons.
To add to what Scott said, I used the following two commands to output clickable stats and spells for the selected token to chat: %{selected|shaped_statblock} @{selected|spells_macro_var} If that is the desired output you are looking for, those would be great resources to see how it could be done with a custom character sheet. Note: This works with the Shaped 5e Character Sheet, along with the Shaped Companion Sheet. It may work with others, that's just my setup.
So, I've been banging my head on this problem for a few days now and have a workable solution.  I'm in the process of tailoring it for my needs. First: The getAttrs(), getSectionIDs() and setAttrs() functions are asynchronous.  I was having difficulty getting the values to return instead of being undefined because, by the time the interpreter got around to using the values the asynchronous functions hadn't returned yet.  This means some backflips and hoops to jump through to ensure you get what you want. I got stuck in callback() hell with my first few naive approaches; you can't just write out your queries in sequential order and expect them to work. I wound up using a Waterfall Design Pattern to iterate through the repeating sections. You can read more about these here: Asynchronous Iterative Patterns [girhub.io] The waterfall ensures that an asynchronous step finishes before the next one starts, taming the asynchronous calls. Pseudocode: on(change:) {      finalResults = ""; First getSectionIDs() returns an array of the repeating fields.    Do some string processing on the entries returned by getSectionIDs() to append the field name to the UIDs. then Sequentially Waterfall() through the array of string-processed field-UIDs:    in the Waterfall, getAttrs() fetches the UIDs+Field Names required.        then do whatever string processing you need on the results from getAttrs.        finalResults = Use the + operater to concatenate the results to finalResults.        when the waterfall is done, you use setAttrs() to set the value of finalResults field. }
I was essentially using the waterfall pattern with my script, but it was taking a couple of seconds to process through each character. On pages with 15+ NPCs, this was too long. My solution was to prompt the user to cut'n'paste a section of commands I would generate (aka @{UID|attr_name} and %{UID|mac_name} ). These commands returned the basic information I need. Capture that output, reformat, and bingo! Near instant capture and processing of large amounts of data! Does this approach sound useful to your situation?
So the script would store the UID value of the repeating sections you want as an attribute, then reference that? Or is there a macro command to fetch a repeating section's ID?
My suggestion above is how I solved a problem for an API script, since this is in the API forum. However, a character sheetworker script...? As for referencing repeating fields, you might want to try thier numeric position. For instance, w/ the Shaped 5e character sheet, the following two commands output the exact same text:  @{Joel|repeating_spell_$0_name} @{Joel|repeating_spell_-KUoBtIEMLxrIV6mC5GL_name} They also have internal helper attributes, which they probably use to cache UIDs. For instance: spells_level_0_macro_var = [Vicious Mockery](~repeating_spell_-kuobtiemlxriv6mc5gl_spell), [Friends](~repeating_spell_-kuocbj3tfqspdqod5nn_spell), [Message](~repeating_spell_-kuocsdlfdantyplxja5_spell) And finally, they have the elaborate attributes/macros I listed above: %{Joel|shaped_statblock} @{Joel|spells_macro_var}