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

Query for repeating roll during roll calculation

1644946574
.Hell
Sheet Author
Hello everyone, I want to have a chat button, that when clicked on, query for an entry of a repeating row and uses a specific button from it. Is that possible? What are good ways to do it if not? Thanks
1644948361
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Custom Roll Parsing can handle this. I've got a few sheets in development that use a pattern like this. Using the K-scaffold 's JS library this would look like: const initiateRoll = function(event){ k.getAllAttrs({ props:['character_name'],//non repeating attributes that needed to be gotten are specified in this array. sectionDetails:[{section:'repeating_sectionname',fields:['name']}],//The details of the repeating sections to get IDs for are defined here. callback:async (attributes,sections)=>{//The callback function to run once all attributes have been retreived. We define this as an async function so we can await the results of startRoll and the k.extractQueryResult function let query = sections.repeating_sectionname.reduce((text,id)=>{ let rollName = attributes[`repeating_sectionname_${id}_name`] text.push(`${rollName},${id}`);//Push the text and id to the array of query prompts return text; },['Use which row']) .join('|');//Join the created array of query info with `|`. let selectedID = await k.extractQueryResult(query);//The k-scaffold provides this function for asking the player for input on the roll. The returned value will be the value of the option in the query that was selected (the id in this case) let roll = await startRoll(`%{${attributes.character_name}|repeating_sectionname_${selectedID}_roll}`) finishRoll(roll.rollId);//We aren't doing anything with this roll, so we just finish it immediately. //The above method assumes that the roll you are calling is a regular roll button. You could also just assemble the roll based on the selected row and send it using the custom roll parsing itself. } }); } on('clicked:my-button',initiateRoll);
1644994788
.Hell
Sheet Author
That looks great. Can you tell me which sheets use it so I can lookup the functionality of extractQueryResults? Thanks
1644997339
GiGs
Pro
Sheet Author
API Scripter
You can do this with old traditional method too. The important thing to ask is - how are you determining which button in the repeating section to draw on?
1645023096
.Hell
Sheet Author
There is only one button. Currently it has no name, but I imagined that giving it a name should solve the issue
1645025910
GiGs
Pro
Sheet Author
API Scripter
Buttons need to have a name to function properly, so it's a good idea to give it a name. Remember to start the name with act_ if its an action button, roll_ if its a roll button. I meant, really, how are you identifying which row in the section to use.
1645028723
.Hell
Sheet Author
That is the initial question. I want to have query popup with alle elements of the repeating query and the user has to choose which one he want to have "clicked"
1645031573
GiGs
Pro
Sheet Author
API Scripter
Do you mean a dropdown on the character sheet? If so, Roll20 doesnt support that kind of dynamic interface.
1645033936
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
.Hell said: That looks great. Can you tell me which sheets use it so I can lookup the functionality of extractQueryResults? Thanks The Rapidfire system sheet uses this, you can also find this utility function (and a lot more) in the utility.js file in the k-scaffold here  (ignore the registration to the kfuncs  object as that's specifically for use within the k-scaffold). GiGs said: Do you mean a dropdown on the character sheet? If so, Roll20 doesnt support that kind of dynamic interface. True, but you can fake it through some CRP magic using roll queries .Hell said: That is the initial question. I want to have query popup with alle elements of the repeating query and the user has to choose which one he want to have "clicked" As I note above, this is possible, but generally a better UX is to just have roll buttons for each repeating item. There's a few reasons to go with this query method of selecting the section though. The reason I've used it several times is because I've been working on systems that allow construction of dice pools based on an array of dynamic skills and attributes.
1645035531
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: GiGs said: Do you mean a dropdown on the character sheet? If so, Roll20 doesnt support that kind of dynamic interface. True, but you can fake it through some CRP magic using roll queries I'd like to know more about that!
1645036419
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Heh, see the code a few posts up for a k-scaffold method! The idea is originally Oosh's, and you can find his write up in the Adventures with Startroll thread . I've changed some of the code from Oosh's original setup, but the same idea is there.