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

Singling out a single die out of a dice pool

1751314712
Arc Dream Publishing
Pro
Marketplace Creator
Compendium Curator
(Crossposting here on another user's recommendation. I am bone-deep ignorant of scripting and mods. Apologies if this is nonsense or in the wrong place.) Our game uses pools of d10s where you look for matching dice. That's easy with  /r 10d10mts   (for 10 dice) or  /r 4d10mts  (for 4 dice).  The tricky part: I also want to pick a random die (the "SNAFU Die") out of that pool (of 10 dice or 4 dice or whatever) and say what it rolled. On a physical table, the SNAFU die would be a different color or size or something so you could easily pick it out. So in theory the output might be: ( 2 + 2 +5+6+9) =1 Match SNAFU Die:  5 Where this hypothetical function rolls 1d5 (the number of dice in the pool) and that comes up 3 for the third die, the "5." Any ideas?
1751317035

Edited 1751317160
Gauss
Forum Champion
To elaborate, I don't think the hypothetical function needs to randomize which is the SNAFU die.  With Scriptcards one die roll can be set as a specific color, just like the physical table.  Example:  You roll 5 dice, one of them is marked as the SNAFU die, just like at your physical table.  The Scriptcard rolls them, it then spits out the number of matches (including the SNAFU die) and the result of the SNAFU die.  I've seen it do this with other cases. :)
1751317576
Arc Dream Publishing
Pro
Marketplace Creator
Compendium Curator
That sounds perfect
1751332614
timmaugh
Forum Champion
API Scripter
Hmm... at one point it sounds like you are picking one of the 1d10 as the SNAFU die... but then later it sounds like you're counting the d10s and rolling one die of THAT hedrality (your 1d5 reference, for 5 d10s). Can you clarify?
1751334216

Edited 1751334295
Gauss
Forum Champion
timmaugh said: Hmm... at one point it sounds like you are picking one of the 1d10 as the SNAFU die... but then later it sounds like you're counting the d10s and rolling one die of THAT hedrality (your 1d5 reference, for 5 d10s). Can you clarify? My understanding is that they didn't realize that one die could be set aside as the SNAFU die while still participating in the match check, so they were suggesting generating which one was the SNAFU die randomly.  Hence my informing them that one die can be set aside as the SNAFU die while still checking all the dice (including SNAFU) for matches. Example:    In this screenshot we have the SNAFU (first d10), plus 4d10 more dice.  Next, we need to check the matches.  While Roll20 can check the number of matches it cannot then also represent the SNAFU die separately. It can do one or the other.  I am envisioning a scriptcard something like this: (default template, but I faked the results since I cannot pull the SNAFU die roll out) @Arc Dream Publishing, is what I've said above accurate?
1751338478
timmaugh
Forum Champion
API Scripter
Ah, I see what you're saying, Gauss. If that kind of output would work... I think you can get there without scripts. And, if scripts are required, I think the Metascript Toolbox should be able to help. I'll look at this tomorrow when I'm fresh/awake.
So I don't really have the skills to help without mods, probably would need RainbowEncoder for that, or with the Metascript Toolbox, that's probably all timmaugh. But if you are looking for a possible way to accomplish this with the ScriptCards Mod, this is one way it could be done: !script {{ --&DieType|d10 --#title|Snafu Die Example --&NumberOfDice|?{How many dice to roll|} --=Rolls|[&NumberOfDice][&DieType] --=SnafuRoll|1d[&NumberOfDice] --&SnafuResult|[$Rolls.RolledDice([$SnafuRoll.Raw])] --&matches|0 --&output| --%i|1;[$Rolls.RollCount] --?[$Rolls.RolledDice([&i])] -eq [&SnafuResult]|[ --&output|+[roll:c][$Rolls.RolledDice([&i])][/roll] --&matches|[= [&matches] + 1] --]|[ --&output|+[roll][$Rolls.RolledDice([&i])][/roll] --]| --%| --+Rolls|[&output] --+Matches|[&matches] }} The above uses a roll query to prompt for the number of dice to roll, rolls that number of d10s, rolls to determine which roll is the snafu results, loops over the results of the rolls to find the number of matches and to format the snafu rolls as critical successes, and then outputs the rolls and the number of matches. That's some sample output from 2 runs with 8d10 rolls. There are a lot of tweaks and changes that could be made but that is an example. Let me know if you have any questions.
1751344181

Edited 1751344271
Gauss
Forum Champion
Thanks Joshua N.,  That output was basically what I was thinking of. I don't have the coding knowledge to write that, but I knew it was feasible. :) Although I think you are still using a random die roll to determine which die is the SNAFU die? I'd probably make it just the first die in the sequence. My understanding is that it is a colored die in gameplay.  Of course, this is all dependent upon what Arc Dream Publishing wants. 
1751396159
Arc Dream Publishing
Pro
Marketplace Creator
Compendium Curator
What we're doing for now is just rolling /mt without sorting and using the first die that comes up as the SNAFU die.
1751396232
Arc Dream Publishing
Pro
Marketplace Creator
Compendium Curator
That looks great Joshua N, thanks. 
Oh do you want the rolls sorted? That is also possible. Definitely possible to make adjustments to how that works.
1751471622

Edited 1751471819
Arc Dream Publishing
Pro
Marketplace Creator
Compendium Curator
Ideally, if there's say a pair of sevens, three sixes, and a pair of nines it says "SETS: 3x6, 2x9, 2x7" (In this game initiative goes in order of the number of dice that match each other [the "width" of a set] and then in order of the value of the matching dice [the "height"]. So the three sixes go first because there's three of them. Then the two nines. Then the two sevens.)
1751482357

Edited 1751482736
Gauss
Forum Champion
Arc Dream Publishing said: Ideally, if there's say a pair of sevens, three sixes, and a pair of nines it says "SETS: 3x6, 2x9, 2x7" (In this game initiative goes in order of the number of dice that match each other [the "width" of a set] and then in order of the value of the matching dice [the "height"]. So the three sixes go first because there's three of them. Then the two nines. Then the two sevens.) Ahhh, that is a whole extra level of detail. Should still be doable in Scriptcards though. So what I am seeing now is this:  The dice are organized into sets, starting with the highest number of matches (3 matches in your example), then organized by die value (2 matches of 9s beats 2 matches of 7s).  Finally, the SNAFU die is also represented separately so you know that it is.  So using your example above lets say we roll 9+SNAFU dice.  We get 6(SNAFU), 2, 9, 4, 7, 10, 7, 6, 6, 9 (10, 9, 9, 7, 7, 6(SNAFU), 6, 6, 4, 2) The Scriptcards presents the following information:  3x6, 2x9, 2x7 SNAFU: 6 Does that sound right?  Do you also need it to display all the dice rolls? 
So I have made some updates to that example ScriptCards earlier. This one has some error checking and some configuration options First off the Configuration Options: --/|Set to a number if you want a specific die to be the snafu die --/|Leave blank if you want to roll randomly for the snafu die --&SnafuDie|1 --&DieType|d10 In this, there is the `&SnafuDie` variable which if you set to 1 like in the example above, will make the first die result, the Snafu Die. This is similar to how you both have described things. If you want to have a random result be the SnafuDie, then leave that variable blank and it will roll for the Snafu. This also lets you change the DieType if needed from d10's. Second, as part of the error checking, I have used a newly added feature of ScriptCards the (isnumeric) String function. This does mean it requires the latest ScriptCards version to be installed from Kurt's repo  in Github  rather than the 1-Click version. That can be removed to work with the 1-Click version as well but it will have less reliable error checking on the input of the Roll Query. Here is some example outputs from runs of 8 dice rolled with the Snafu die hardcoded to the first die: It is currently set to print each roll, then print the Sets in order of width and then height as described. then finally print the Snafu result and the number of matches found for the Snafu result. Here is the updated ScriptCard. I did add some comments to hopefully explain the sections rather than the pretty terse ScriptCard example I posted earlier: !script {{ --/|CONFIGURATION VARIABLES --/|Set to a number if you want a specific die to be the snafu die --/|Leave blank if you want to roll randomly for the snafu die --&SnafuDie|1 --&DieType|d10 --#title|Snafu Die Example --/|This will always prompt for the number of dice --/|Roll20 Roll Queries are always processed first by Roll20 before ScriptCards runs --&NumberOfDice|?{How many dice to roll|} --/|ScriptCards 3.0.12 added the isnumeric string function which is used in the error checking --/|If you want to use the current 1-Click version of ScriptCards then you will need to remove that check --?[&SC_VERSION_NUMERIC] -lt 300120|>LogMessage;fatal;ScriptCards Upgrade Required;At minimum ScriptCards version 3.0.12 is required but you are running [&ScriptCards_Version] --/|Some error checking to make sure we have a positive number of dice to roll --?"[&NumberOfDice]" -lt 1 -or "[&NumberOfDice(isnumeric)]" -eq 0|>LogMessage;fatal;Positive Integer Required;ERROR;Please enter a positive integer value for the number of dice to roll. Entered [&NumberOfDice] --=Rolls|[&NumberOfDice][&DieType] --/|SnafuDie is not hard-coded, roll randomly for Snafu --/|If SnafuDie is hard-coded, check if the number is not higher than the number of dice entered --/|If SnafuDie is higher than the number of dice entered, then set SnafuDie to the number of dice entered, so the last die --?"[&SnafuDie]X" -eq "X"|[ --&SnafuDie|[= 1d[&NumberOfDice] ] --]|[ --?[&SnafuDie] -gt [&NumberOfDice]|&SnafuDie;[&NumberOfDice] --]| --&SnafuResult|[$Rolls.RolledDice([&SnafuDie])] --/|Create some variables to store results from our loop --/|Create a hashtable to store the count of the results --/|Create a string variable that will get appended each output for the rolls --~|hash;set;Results --&rollsOutput| --%i|1;[$Rolls.RollCount] --?[$Rolls.RolledDice([&i])] -eq [&SnafuResult]|&rollsOutput;+[roll:c][$Rolls.RolledDice([&i])][/roll]|&rollsOutput;+[roll][$Rolls.RolledDice([&i])][/roll] --h:Results("[$Rolls.RolledDice([&i])]")|[= [:Results("[$Rolls.RolledDice([&i])]")] + 1] --%| --/|With the roll results processed, loop through the results to find any and all sets --/|Sets will then be sorted in descending order to process the highest set first --~|array;define;Sets --~|array;fromkeys;ResultKeys;Results --%j|foreach;ResultKeys --?[:Results("[&j]")] -ge 2|>libArray_Push;Sets;[:Results("[&j]")]x[&j] --%| --~|array;numericsort;Sets;desc --/|If there are no sets rolled, then return a message otherwise return a comma separated list --?[@Sets(length)] -gt 0|[ --~setOutput|array;stringify;Sets;, --]|[ --&setOutput|No sets rolled --]| --/|Display the output for rolls, sets, and snafu --+Rolls|[&rollsOutput] --+Sets|[&setOutput] --+Snafu|[b]Result:[/b] [&SnafuResult] [b]Matches:[/b] [:Results("[&SnafuResult]")] --:Done| --X| --:LogMessage|MessageLevel;EmoteText;MessageTag;MessageContent --#emoteText|[%2%] --+[%3%]|[%4%] --?"[%1%]" -eq "fatal"|Done --<| --:libArray_Push|ArrayName;StringValue --~|array;add;[%1%];[%2%] --<| }} Let me know if you have any questions or if I misunderstood the desired output.
1751491957
Gauss
Forum Champion
Joshua, that looks good based on my understanding of Arc Dream Publishing's needs. Nice job!