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

Way to choose from repeating sections during Roll?

What I would like to do is add a modifier to a skill check based upon the level of an "interest" the player may have in a repeating section. Example: Dirk is scouring some financial statements in search of evidence. He rolls his Analyze skill and picks a context/interest from the repeating interests of "Finance". The skill he's rolling has a base value of 35, and he gets a bonus from using Finance of +10 because of his rank in Finance. This gives him a total target number of 45 to roll under. Is there a way to do this using rolls on the character sheet? API? Any advice or direction would be appreciated. I think I saw a post from two years ago with someone asking for this sort of feature, and I don't know if it's possible yet.
1548502842
GiGs
Pro
Sheet Author
API Scripter
If I understand you correctly, it's definitely possible to do this with the API. There are two ways at least to build the script: 1) Dynamically, when the skill roll is made, the script scans the character sheet, builds a dropdown list, and collects the input. This is a little tricky to build. 2) Statically: have a script that monitors the repeating section for changes. Whenever it changes, it creates a new list stored in an Ability or Attribute. Your skill roll macro then includes that list automatically. (I have done essentially the same thing in one of my campaigns.)  If you're using a custom sheet, you can also do this with a sheet worker. I'm half-asleep right now so i cant give points for the code just yet. If you post your current skill roll macro, and the relevant attribute names from the fieldset, and say how you want to do it, I'll have a look when I check back in later.
1548517295
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
In addition to GiGs' API methods, you could do this sans API by having each skill roll output a chat menu of the contexts/interests available and then the actual roll would come from clicking the desired context/interest. This would require a sheetworkers to assemble and maintain as repeating sections are added.
1548547262

Edited 1548548942
Thank you for the help! Yes I am using a custom character sheet.  I don't actually have much unique set up for the rolls yet, and here's one of them as an example:         <span name="attr_skill_medical_base"  ></span><em>Medical</em><input type="number"  name="attr_skill_medical_training"><span  name="attr_skill_medical_total"></span>         <button type='roll' name='roll_testattack' value='&{template:default} {{name=@{character_name}}} {{result=[[1d100 + @{skill_medical_total}]]}}'></button> I have a "universal" sheet worker that sums the attr_skill_medical_base + attr_skill_medical_training = attr_skill_medical_total Here is what the repeating section looks like:         <fieldset class="repeating_context">             <select name="attr_interest_rank" class="context_rank">                 <option value="1">NOVICE</option>                 <option value="2">EXPERT</option>                 <option value="3">MASTER</option>             </select>             <input type="text" name="attr_interest_name" class="context_name"/>         </fieldset> To basically repeat what I am looking to try to do... I want the player to click the roll button next to "Medical" and then pick a context from his repeating list of contexts . The player's rank in that particular context would grant a bonus based on its value (like maybe 10x the value) Ultimately what I want to do is more complicated, but I think sorting this out first is the priority.
1548549870
GiGs
Pro
Sheet Author
API Scripter
Primus said: Here is what the repeating section looks like:         <fieldset class="repeating_context">             <select name="attr_interest_rank" class="context_rank">                 <option value="1">NOVICE</option>                 <option value="2">EXPERT</option>                 <option value="3">MASTER</option>             </select>             <input type="text" name="attr_interest_name" class="context_name"/>         </fieldset> To basically repeat what I am looking to try to do... I want the player to click the roll button next to "Medical" and then pick a context from his repeating list of contexts . The player's rank in that particular context would grant a bonus based on its value (like maybe 10x the value) Ultimately what I want to do is more complicated, but I think sorting this out first is the priority. The first change I'd suggest is changing the dropdown values to equal whatever the modifier is, like              <select name="attr_interest_rank" class="context_rank">                 <option value="0">NOVICE</option>                 <option value="10">EXPERT</option>                 <option value="20">MASTER</option>             </select> Obviously I don't know what the actual numbers should be.
1548561165

Edited 1548561272
Alright. I feel like I have made some decent progress. Right now I have a list of the names/ranks of each entry in the repeating list. So I could easily store that in some format or another in an attr I have created for the purpose.     on( "change:repeating_context remove:repeating_context remove:repeating_context", function () {         getSectionIDs("context", function(idarray) {             var contextList = [];             for(var i=0; i < idarray.length; i++) {                 var contextName = "repeating_context_"+idarray[i]+"_name";                 var contextValue = "repeating_context_"+idarray[i]+"_rank";                 contextList.push(contextName, contextValue);             }             console.log( contextList.toString() );                          getAttrs( contextList, function(values){                 var vals =  Object.values(values);                 console.log( vals.toString() );             });         });     }); When I run this with a repeating_context section that has three entries, I get the expected two console messages: repeating_context_-lxc9dsijaafcu0hmpnp_name,repeating_context_-lxc9dsijaafcu0hmpnp_rank,repeating_context_-lxc9uiwsvkrjt7d4iul_name,repeating_context_-lxc9uiwsvkrjt7d4iul_rank,repeating_context_-lxc9yt34kynia6lgzng_name,repeating_context_-lxc9yt34kynia6lgzng_rank Craft,10,Program,10,Repair,20 So I think the next step is to save that in a string that can be used in as roll query. The output of that would look something like this: ?{Pick a Context|Craft,10|Program,10|Repair,20} So then what? Lets assume I save that in a hidden input called attr_context_query; how do I use that in my roll? I feel like I am really close!
Hey, I figured it out! Here is my HTML and script from my test character sheet. Add a context to the repeating section Name the context, like "Bows" Set the rank, such as MASTER Click the roll button next to the Aim skill and pick a your context to roll. <div class="3colrow">     <label>Aim: </label><input type="number" name="attr_aim" value="30"/>     <button type='roll' name='roll_testattack' value='&{template:default} {{name=@{character_name}}} {{result=[[1d100 + @{aim} + @{context_list}]]}}'></button> </div> <div class="3colrow">     <fieldset class="repeating_context">         <select name="attr_rank" class="context_rank">             <option value="10">NOVICE</option>             <option value="20">EXPERT</option>             <option value="30">MASTER</option>         </select>         <input type="text" name="attr_name" class="context_name"/>     </fieldset> </div> <input type="hidden" name="attr_context_list" value="?{Context|none,0|empty,0}" /> <script type="text/worker">     on( "change:repeating_context remove:repeating_context sheet:opened", function () {         getSectionIDs("context", function(idarray) {             var contextList = [];             for(var i=0; i < idarray.length; i++) {                 var contextName = "repeating_context_"+idarray[i]+"_name";                 var contextValue = "repeating_context_"+idarray[i]+"_rank";                 contextList.push(contextName, contextValue);             }             console.log( contextList.toString() );                          getAttrs( contextList, function(values){                 var vals =  Object.values(values);                 console.log( vals.toString() );                                  var query = "?{Context|none,0";                 if( vals.length <= 0 ){                     query = query + "|empty,0";                 }else for( var i=0;i< vals.length; i+=2 ){                     query = query + "|" + vals[i] + "," + vals[i+1];                 }                 query = query + "}";                 console.log( query );                 setAttrs({ context_list: query });             });         });     }); </script> Next I need to separate out the name and the value so that I can display the context name as part of the roll template. Hmm looks like I also need to display the name of the skill rolled.
I am stuck again. A query like this: ?{Pick a Context|Craft,10|Program,10|Repair,20} Gives a value (eg 20) from the name (eg Repair) a player selected as a bonus to my roll. However, I want to know the name the player selected and display it in the roll template. Is this even possible?
1548573891

Edited 1548585185
GiGs
Pro
Sheet Author
API Scripter
Nice work. Edit: ignore this post, I had a brainfart! I havent tried the script, but I don't think you need the getAtrrs function at all, since you don't look for the actual values of the attributes, you just want their names. So this should work: on( "change:repeating_context remove:repeating_context sheet:opened", function () { getSectionIDs("context", function(idarray) { var query = "?{Context|none,0"; for(var i=0; i < idarray.length; i++) { var contextName = "repeating_context_"+idarray[i]+"_name"; var contextValue = "repeating_context_"+idarray[i]+"_rank"; query = query + "|" + contextName + "," + contextValue; } query = query + "}"; console.log( query ); setAttrs({ context_list: query }); }); }); Here is a more compact version that I think  will work, using more modern syntax (I'm still learning these functions, but I think it's correct). on( "change:repeating_context remove:repeating_context sheet:opened", function () { getSectionIDs("context", function(idarray) { let query = idarray.reduce((str, id) => str + `|repeating_context_${id}_name,repeating_context_${id}_rank`,'{Context|none,0'); query += "}"; console.log( query ); setAttrs({ context_list: query }); }); }); Next I need to separate out the name and the value so that I can display the context name as part of the roll template. Hmm looks like I also need to display the name of the skill rolled. Since you have the context name in the sheet worker, you could output a second attribute for that part.
1548574075
GiGs
Pro
Sheet Author
API Scripter
Primus said: I am stuck again. A query like this: ?{Pick a Context|Craft,10|Program,10|Repair,20} Gives a value (eg 20) from the name (eg Repair) a player selected as a bonus to my roll. However, I want to know the name the player selected and display it in the roll template. Is this even possible? Unfortunately this just isn't possible. With basic macros, you can't use reuse queries like that.  As a pro user you could use an API script to replace the rolltemplate, and report both the value and the name. If the sheet is going to be shared publicly, that feature wont be available to free users.
1548575391

Edited 1548575512
Okay thanks for the feedback. I am still going to try. I feel like a hacker today :P I'll tell you what I am trying and maybe you can save me some headache. Instead of saving the pairs like this ?{Pick a Context|Craft,10|Program,10} I am saving them in an attr like this: ?{Pick a Context|Craft,repeating_context_-lxc9dsijaafcu0hmpnp|Program,repeating_context_-lxc9uiwsvkrjt7d4iul} The plan is that when the player picks a context I'll save the ID information of the repeating context they chose. What I am hoping to be able to do is to add the _name or _rank within the roll definition somehow. It might look something like this: &{template:default} {{name=@{@{context_list}_name}}} {{result=[[1d100 + @{aim} + @{@{context_list}_rank} ]]}} Do you think this might work? If so what's the right syntax for a double replacement like this? EDIT: I didn't see your first response, studying that now.
1548577376
GiGs
Pro
Sheet Author
API Scripter
Primus said: What I am hoping to be able to do is to add the _name or _rank within the roll definition somehow. It might look something like this: &{template:default} {{name=@{@{context_list}_name}}} {{result=[[1d100 + @{aim} + @{@{context_list}_rank} ]]}} Do you think this might work? If so what's the right syntax for a double replacement like this? Are you referring to in a standard macro, or making an API script? If a standard macro, it's just not possible. At all.
As expected, that resulted in a couple errors No attribute was found for @{Friheebro Thescatu|@{context_list} No attribute was found for @{Friheebro Thescatu|@{context_list} TypeError: Cannot read property 'substring' of undefined &{template:default} {{name=@{@{context_list}_name}}} {{result=[[1d100 + @{aim} + @{@{context_list}_rank} ]]}}
1548577650
GiGs
Pro
Sheet Author
API Scripter
I replied just before you posted. That wont work. There is just no way to do what you are trying to do here, without a custom API script to replace the roll.
GiGs said Are you referring to in a standard macro, or making an API script? If a standard macro, it's just not possible. At all. Macro that's part of a button type=roll. I was hoping to not have to make it API. I haven't started learning that yet. Though I definitely need to for some other functionality I want.
1548579196
GiGs
Pro
Sheet Author
API Scripter
APIs and sheet workers are based on the same programming language (javascript). There are some differences, but there are more similarities. It's nowhere near as simple to use as a dice macro, but some things cant be done any other way. But often if using the API, you dont need to write a script, someone else will have done it already. I think the Power Cards API script might be able to do what you want with the dropdown query, but you'll have to seek help from people familiar with using it. There's a thread in the API forum for it, if you want to check it out.
Thanks for all your help. I will start looking at how to use the API and Power Cards specifically.
1548583688
Finderski
Plus
Sheet Author
Compendium Curator
If you don't need the context to be visible in chat, but want to know what they selected, you could change this line:  query = query + "|" + vals[i] + "," + vals[i+1]; to this:  query = query + "|" + vals[i] + "," + vals[i+1]+"["+vals[i]+"]"; That will add a comment to the roll, so when you hover over the roll, you'd be able to see to the formulas used and that comment would indicate which context they selected.  Just one, non-API way of getting the info so it's available, even if not immediately visible.
1548584265

Edited 1548584412
GiGs
Pro
Sheet Author
API Scripter
That's a good idea. That also made me realise I was wrong earlier when I suggested an alternate version of the script. You do use the values. I dn't know what I was thinking!