Exploding dice results

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Exploding dice results

Post by Irrlicht »

Using the XdYe dice expression, for example 5d6e, I get just the total.
Using XdYo (5d6o), I get: "Dice: 15, 1, 1, 3, 5, Maximum: 15"; basically, a string (in fact, if I use 1d20e + 5d6o, I get the string immediately after the d20 result). If I have to use it often (which I'll have), it would be quite annoying to alway use a function to extract the single rolls, remove the string, and add them up.

So, the question is: what would be the best way to get both the single exploded rolls and their sum?
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Exploding dice results

Post by aliasmask »

I'm sure there's code around here showing how to do it. I know I've written stuff similar, but this may be what you're looking for: http://forums.rptools.net/viewtopic.php ... ng#p197114

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: Exploding dice results

Post by JamzTheMan »

If I were to tackle it, I would probably just use a for-loop, doing one exploding die at a time, tracking total, and, individual rolls. (although a regular expression replace could probably be done on the other string to strip and sum.

In any case, yes, create a macro, then define it as a UDF like, explodeMyDice(num, sides), if sides is needed. Have it either return a formatted output if that's what you need, or if you need to do more work, return a json with {total:sumOfResult, rolls:"1,4,2,5"}.

Of course, rolls: could also be an array []. It all depends on what you are doing with the results...
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

Post Reply

Return to “Macros”