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

Rolling higher-than and lower-than simultaneously

1647130927

Edited 1647131161
GiGs
Pro
Sheet Author
API Scripter
It looks like you are still editorialising - that whole html is inside a single fieldset, and there is no script block for your sheet workers at the end. It might be enough to get a better grasp of what you're going for, but the whole sheet would still be helpful (don't worry about bad coding). I won't have time to look at the sheet till tomorrow, so you have time :) PS: the fact that your action buttons have an uppercase letter in their name (Cap) might be the reason your code wasn't working. If so, this is why it's necessary to show the actual code you are using.
Wow, well if you're sure... <a href="https://docs.google.com/document/d/1ocH3jQLPasZjecnccRF9H_rYtfqWbdAA1wvRt5wM7UM/edit?usp=sharing" rel="nofollow">https://docs.google.com/document/d/1ocH3jQLPasZjecnccRF9H_rYtfqWbdAA1wvRt5wM7UM/edit?usp=sharing</a> Maybe the uppercase letters are problematic, and I should probably get rid of them anyway, but as I can't get it to work with even the simplest example (above) I've not even tried to do it on the sheet itself.
And thanks again for your efforts and patience!
1647302728

Edited 1647302805
GiGs
Pro
Sheet Author
API Scripter
I'm looking at the code now, and it seems you have 10 separate macros, each with the same variables - like this: &nbsp; const total1s = dice . filter ( d =&gt; d === 1 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const total2s = dice . filter ( d =&gt; d === 2 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const total3s = dice . filter ( d =&gt; d === 3 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const total4s = dice . filter ( d =&gt; d === 4 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const total5s = dice . filter ( d =&gt; d === 5 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const total6s = dice . filter ( d =&gt; d === 6 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const nmiss = dice . filter ( d =&gt; d &lt; 4 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const nweak = dice . filter ( d =&gt; 3 &lt; d ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const totalz1s = dicez . filter ( d =&gt; d === 1 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const totalz2s = dicez . filter ( d =&gt; d === 2 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const totalz3s = dicez . filter ( d =&gt; d === 3 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const totalz4s = dicez . filter ( d =&gt; d === 4 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const totalz5s = dicez . filter ( d =&gt; d === 5 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const totalz6s = dicez . filter ( d =&gt; d === 6 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const nmissz = dicez . filter ( d =&gt; d &lt; 4 ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const nweakz = dicez . filter ( d =&gt; 3 &lt; d ). length ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const high = Math . max (... dice ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const low = Math . min (... dice ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const highz = Math . max (... dicez ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const lowz = Math . min (... dicez ); &nbsp; &nbsp; &nbsp; &nbsp; It's very likely to can combine all of those into a single forEach loop (and get by with a lot fewer variables too). If I knew exactly what they were doing I could help you there. I think youre problem here is you are not approaching the issue efficiently (and its not a unique problem, lots of inexperienced askers do this, but not usually to this scale!). You are trying to guess what code you need, and asking incremental questions to help your guesses, but you don't know the code so you are asking the wrong questions. If instead you described what you were trying to achieve, fully, from begining to end, we could provide a complete solution and describe exactly how it works. Anyway back to your last question. I don't see anywhere in the code where you have a variable like this: const stats = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fight: "Fighting", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dodge: "Ducking" &nbsp; &nbsp; &nbsp; &nbsp; }; and I see you have created this rolltemplate &lt;rolltemplate class="sheet-rolltemplate-diceroll"&gt; &nbsp; &nbsp; {{name}}&lt;br /&gt; &nbsp; &nbsp; {{computed::term}}&lt;br /&gt; &nbsp; &nbsp; {{computed::roll}}&lt;br /&gt; &nbsp; &nbsp; {{computed::highest}}&lt;br /&gt; &nbsp; &nbsp; {{computed::lowest}} &lt;/rolltemplate&gt; but I don't see anywhere in the code where you are actually using it. So it's hard to find a problem with the code if it doesn't exist. PS - if you share your code again, please use either pastebin.com or gist.github.com - its much easier to grab the code out of those.
1647303205

Edited 1647303399
GiGs
Pro
Sheet Author
API Scripter
As an unrelated gift, you have a lot of workers like this: on ( 'clicked:cleargumption' , function () { &nbsp; &nbsp; getAttrs ([ 'gumption1 gumption2 gumption3 gumption4 gumption5 gumption6' ], function ( values ) { &nbsp; &nbsp; &nbsp; &nbsp; setAttrs ({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gumption1: 0 , &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gumption2: 0 , &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gumption3: 0 , &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gumption4: 0 , &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gumption5: 0 , &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gumption6: 0 &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp;}); }); The getAttrs line is wrong, you need separate quotes for each attribute, like: &nbsp; &nbsp; getAttrs(['gumption1', 'gumption2', 'gumption3', 'gumption4', 'gumption5', 'gumption6'], function(values) { But when you arent reading the value of an attribute, you are just overwriting it, so you dont need to use getAttrs at all. You use that only to read the value of attributes from the character sheet. on ( 'clicked:cleargumption' , function () { &nbsp; &nbsp; setAttrs ({ &nbsp; &nbsp; &nbsp; &nbsp; gumption1: 0 , &nbsp; &nbsp; &nbsp; &nbsp; gumption2: 0 , &nbsp; &nbsp; &nbsp; &nbsp; gumption3: 0 , &nbsp; &nbsp; &nbsp; &nbsp; gumption4: 0 , &nbsp; &nbsp; &nbsp; &nbsp; gumption5: 0 , &nbsp; &nbsp; &nbsp; &nbsp; gumption6: 0 &nbsp; &nbsp; }); });
The getAttrs line is wrong, you need separate quotes for each attribute, like: Thanks, missed that. I've never removed a getAttrs line because I didn't know whether or not the whole line was unnecessary if I don't need the values. Good to know.
I'm looking at the code now, and it seems you have 10 separate macros, each with the same variables Primarily because they're mostly using subtly different rolltemplates. I started by trying to incorporate them all into one giant rolltemplate but that got reeeeeally big and repetitive real quick. Easier to copy, paste and tweak each time. I'm sure they are less than efficient, but they're doing exactly what I need them to so not worth anyone's time or effort.
I don't see anywhere in the code where you have a variable like this: Well no, like I said I haven't tried to do it in the sheet proper. I know the code you gave me works outside repeating sections but not inside so I've been addressing that general hurdle before involving all the situational nuances and names that have to be just right. I.e. If it just can't be done the same way because a repeating section would need a very different form of sheetworker to do the same thing then it would be quicker to learn that without a dozen other things that could also be the reason it doesn't work.
You are trying to guess what code you need, and asking incremental questions to help your guesses, but you don't know the code so you are asking the wrong questions. Guilty as charged. I think I find it easier to pick stuff up through bite-size tips that I can play around with than comprehensive case studies tailored to specific situations that I'm going to have to explain in full whenever I need help to apply one to a slightly different situation. Sure I might get a deeper understanding the latter way, but you'd have to explain it right down at the character-by-character level to compensate for my lack of fluency. More importantly, expecting you to spend god-knows-how-long to do my (in the grand scheme of things) ultra-trivial work for me from start to finish feels supremely unreasonable, and so I just end up asking for nudges here and there. If instead you described what you were trying to achieve, fully, from begining to end, we could provide a complete solution and describe exactly how it works. Again, if you're sure... The purpose of this part of the sheet is to provide a repeating section for the party's captains (henchmen). Each one can be a leader and/or an expert, each of which type costs two upgrade points, and there needs to be a hide/reveal notes section. Each captain gets four out of the twelve possible skills (fight ... hustle) and each captain can have a different variation. In each of their skills a captain has a rating between 0 and 3. But twelve skills and ratings per captain would be a bulky/cluttered mess so I'm after a way for players to select from the full menu but only display the chosen four (currently I have a hide/reveal section with all twelve options with checkboxes to reveal the corresponding skill button and rating, with an intricate system of sheetworkers and hide-reveal sections to make the chosen four display compactly). Captains can make rolls on these skills, hence the need for rollbuttons, and these rolls are identical to the ones the players make using their own attributes. I've already covered the player version (the sheetworker beginning&nbsp; const stats = [ &nbsp; &nbsp; 'Fight', &nbsp; &nbsp; 'Growl', ... ) which I also don't know how to apply to a repeating section, but I'm trying to deploy your second method instead so that the corresponding rolltemplate can determine the skill used by the button that was clicked. Each captain also needs a fifth 'Other Action' button which rolls 0 dice (see below) for when the captain is using one of the eight skills they don't have. Currently the repeating section and associated sheetworkers are doing all of this except the rolls. However, recent testing has shown that a sheetworker (probably) won't retrieve what I need from a hide/reveal section within a table within a repeating section within another table, but will (probably) get it from just a repeating section in a table so some re-design of the skill-display and entity-alignment will (probably) be required there. Here's what a roll needs to do (and tell the rolltemplate in a way that can be used for selective display): – Roll a pool of d6 equal to the rating of the skill – Provide a pop-up to add bonus d6s (can be negative) to the pool – Determine whether the highest number was a 6, between 4 and 5, or less than 4 – Know whether or not the results contain multiple 6s – Return all the dice results (for rolltemplate display using images) – Identify who made the roll (i.e. name of the captain, which is an input within the repeating section) – Identify the skill rolled – Provide another pop-up to identify the 'Position' of the roll ('Controlled', 'Risky', 'Desperate') or that it's to 'Gather Information' – Where skill rating+bonus is 0, instead of rolling 0d6 the sheetworker must roll 2d6, identify the lowest result instead of the highest and let the rolltemplate know that it's a zero-dice roll rather than a standard 2d6 roll (so where it looks like the existing rollbutton sheetworkers are doing the same thing twice over, all the elements appended with a 'z' are for the zero-roll version, which the rolltemplate can easily refer to instead whenever skill rating+bonus is equal to 0) And I think that's all!
Contingency: My back-up is for the buttons in the repeating section to populate generic inputs outside the repeating section (name of the captain, name of the skill, rating of the skill) for a single button to refer to for the roll (which could potentially just use the player-version of the rolling sheetworker). I.e. To roll 'fight' for 'Captain A' the user would first click the 'fight' button in that row of the repeating section to extract the required information and then click the generic roll button outside the repeating section to use said information for the roll. So if the above simply isn't possible/feasible then I'd greatly appreciate help with how to do this.
1647332406
GiGs
Pro
Sheet Author
API Scripter
Aero said: You are trying to guess what code you need, and asking incremental questions to help your guesses, but you don't know the code so you are asking the wrong questions. Guilty as charged. I think I find it easier to pick stuff up through bite-size tips that I can play around with than comprehensive case studies tailored to specific situations that I'm going to have to explain in full whenever I need help to apply one to a slightly different situation. I understand what you're saying, but when you are trying to guess what you need, you might guess wrong and your questions may lead you to getting answers that make your job more complicated. When you post the full goal, someone can see more efficient ways to achieve that goal, and break it down into smaller steps for you. That looks like a good description - I'll have a look at that tomorrow.
1647332546
GiGs
Pro
Sheet Author
API Scripter
Aero said: I don't see anywhere in the code where you have a variable like this: Well no, like I said I haven't tried to do it in the sheet proper. I know the code you gave me works outside repeating sections but not inside so I've been addressing that general hurdle before involving all the situational nuances and names that have to be just right. I.e. If it just can't be done the same way because a repeating section would need a very different form of sheetworker to do the same thing then it would be quicker to learn that without a dozen other things that could also be the reason it doesn't work. The problem is, I don't understand why the code you are using isn't working - because it should work, so I cant figure out what's going wrong without seeing what code you are using. A repeating section does need slightly different code than a non-repeating code, but I gave the modified version that does work with a repeating section. So I'm missing some information.
1647332691

Edited 1647332885
GiGs
Pro
Sheet Author
API Scripter
Aero said: The getAttrs line is wrong, you need separate quotes for each attribute, like: Thanks, missed that. I've never removed a getAttrs line because I didn't know whether or not the whole line was unnecessary if I don't need the values. Good to know. The important thing to understand: getAttrs literally means "get attributes" - if you don't need to get the attributes, you don't need it. Remember sheet workers know nothing: they don't know anything about the rest of the character sheet. So you use getAttrs when you want to use attribute values from the sheet. If you don't need to read their current values- such as when you are simply overwriting them or clearing them - you don't need getAttrs.
A repeating section does need slightly different code than a non-repeating code, but I gave the modified version that does work with a repeating section. Do you mean this?: If everying affected by the worker is on the same row (the buttons, the attributes you read the values of, and the attribute you save to), then you can probably just replace every instance of ${button} in the last worker with repeating_action_${button} (Except those in the startRoll text - that line should remain unchanged). If so, I tried the following (and variations) and can't make it work: &lt;fieldset class="repeating_action"&gt; &lt;button type="action" type="number" name="act_fight" style="text-align:center;"&gt;FIGHT&lt;/button&gt;&nbsp; &lt;input name="attr_fight" type="number" /&gt;&lt;br /&gt; &lt;button type="action" type="number" name="act_dodge" style="text-align:center;"&gt;DODGE&lt;/button&gt;&nbsp; &lt;input name="attr_dodge" type="number" /&gt; &lt;/fieldset&gt; &lt;rolltemplate class="sheet-rolltemplate-diceroll"&gt; &nbsp; &nbsp; {{name}}&lt;br /&gt; &nbsp; &nbsp; {{computed::term}}&lt;br /&gt; &nbsp; &nbsp; {{computed::roll}}&lt;br /&gt; &nbsp; &nbsp; {{computed::highest}}&lt;br /&gt; &nbsp; &nbsp; {{computed::lowest}} &lt;/rolltemplate&gt; &lt;script type="text/worker"&gt; const stats = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fight: "Fighting", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dodge: "Ducking" &nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; &nbsp; &nbsp; Object.keys(stats).forEach(button =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on(`clicked:repeating_action_${button}`, () =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getAttrs([`repeating_action_${button}`], v=&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startRoll(`&amp;{template:diceroll} {{name=${button}}} {{roll=[[(@{${button}})d6s]]}} {{highest=[[0]]}} {{lowest=[[0]]}} {{term=[[0]]}}`, (diceroll) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const term = stats[button]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const total = diceroll.results.roll.result &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const dice = diceroll.results.roll.dice //This will be an array of the values rolled on all the dice &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const high = Math.max(...dice); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const low = Math.min(...dice); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finishRoll( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; diceroll.rollId, // this is where you save the computed values into something that can be passed to rolltemplates. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; roll: total, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; highest: high, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lowest: low, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; term: term &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; }); &lt;/script&gt; &nbsp;(And again I'm going the quick, abstract route rather than spending hours tailoring it to a highly specific situation, but you already have the full specifications now).
1647340532
GiGs
Pro
Sheet Author
API Scripter
I did mean that, and I see I made an error in the original code. This line on(`clicked:repeating_action_${button}`, () =&gt; { should be on(`clicked:repeating_action:${button}`, () =&gt; { It's irritating that the event line and the getAttrs line use different syntaxes for repeating section attributes - it's so easy to make that mistake.
Ah man, even I should've caught that! Whoops. Still not the whole story though because it's not rolling the right number of dice. The character sheet I was using for testing had fight and dodge set to 7 and 3 respectively and the sheetworker will only roll those numbers of d6 no matter what new rows I create or what I set the new stats to. Even changing the first row's values (or deleting it) doesn't help – 7d6 for fight and 3d6 for dodge every time. And if I create a new character sheet and test it out there it comes up with the same errors as before: No attribute was found for @{Character 2|fight} SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-] or [0-9] but "C" found. I did a quick test by putting an input called fight outside the repeating section and it worked fine, rolling the right number of dice too, so presumably something needs to change in the startRoll line to tell it look in the repeating section for the stat with the same name as the button.
1647381992
GiGs
Pro
Sheet Author
API Scripter
Aero said: I did a quick test by putting an input called fight outside the repeating section and it worked fine, rolling the right number of dice too, so presumably something needs to change in the startRoll line to tell it look in the repeating section for the stat with the same name as the button. Aha, that makes sense. In the pre-startRoll days, you could use code like I did, and it would work, but Custom Roll Parsing (and Action buttons might need the context of the button (the repeating section and row number being supplied). I'll have to do some testing, and think about the best way to handle that.