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

Dice Macros

Could anyone help me out here :) I am trying to add a small mini game where you compare two sets of dice rolls, without adding the total.  I have this working fine [[1d6]] | [[1d6]] | [[1d6]] | [[1d6]]  The thing i can't figure out is, can the dice be lined up automatically from highest to lowest. To make it easier to compare both sets. 
1674022331
Kraynic
Pro
Sheet Author
The easiest way to do that would be to not use inline rolls: /r 4d6sd That will roll 4d6 and sort descending.  It will give the total as well, but all the individual dice rolled will be displayed above the total. If you absolutely can't have the total, then you might check out the script cards api (and the thread for it in the mod/api forum).  It wouldn't surprise me if it is possible to roll individual dice with that script and have it sort them.
1674044211
David M.
Pro
API Scripter
Here is a link to a Scriptcard bubble sorting algorithm. That example is hardcoded to sorting ascending, but you can change the -gt line that calls the BubbleUp function to read -lt instead to sort descending, e.g.                     --?[$Roll[$i.Total]] -gt [$Roll[$j.Total]] |>BubbleUp;[$i.Total];[$j.Total] should be changed to: --?[$Roll[$i.Total]] -lt [$Roll[$j.Total]] |>BubbleUp;[$i.Total];[$j.Total] If you have a variable number of rolls it gets a little more complicated. I thought I had a version that did this but can't seem to put my hands on it. Another approach could be assigning the rolls to an array, performing an array;sort function on it, and reassigning to roll variables in a loop. The scriptcards wiki has more info on this in the " Built-in Functions " section.
1674045919
David M.
Pro
API Scripter
Ok, I just whipped up a quick example using the array sorting method !script {{ --#title|Sort Descending with Arrays --=numRolls|?{How many dice?|4} --&dieType|?{Die Type?|d4|d6|d8|d10|d12|d20} --#leftsub|[$numRolls][&dieType] Example --:POPULATE THE ARRAY| --%i|1;[$numRolls.Raw];1 --=thisRoll|1[&dieType] --?[&i] -eq 1|[ -->InitializeArray|[$thisRoll.Raw] --]|[ --~|array;add;myArray;[$thisRoll.Raw] --]| --%| --:***********You can delete this section if you want************| --:BUILD A STRING OF ROLLS TO PRINT ON ONE LINE| unsorted rolls --=maxIndex|[$numRolls]-1 --%i|0;[$maxIndex.Raw];1 --=thisRoll|[@myArray([&i])] --&unsortedResults|+[$thisRoll] --%| --+Unsorted Rolls|[&unsortedResults] --:***************************************************************| --:SORT THE ARRAY| --~|array;numericsort;myArray;descending --:BUILD A STRING OF ROLLS TO PRINT ON ONE LINE| sorted rolls --=maxIndex|[$numRolls]-1 --%i|0;[$maxIndex.Raw];1 --=thisRoll|[@myArray([&i])] --&sortedResults|+[$thisRoll] --%| --:PRINT RESULTS| --+Sorted Rolls|[&sortedResults] --X| End Macro --:InitializeArray| accepts the first roll as a parameter --~|array;define;myArray;[%1%] --<| }}
Thanks for the help i will give it a shot!