#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Exploding Dice

edited February 2014
I'm working on a roller for the BASH! RPG, and I've come up against a problem.

When doubles are rolled in BASH, dice explode - if the two d6s you're rolling match, roll another d6 and add it to the result, and, if THAT d6 either result, roll again etc.

So this is the code I have so far:
```Table: BASH Roll
Set: var1 ={1d6}

Set: var2 ={1d6}

Set: var3 ={1d6}

Define: vart ={!{\$var1}+{\$var2}}
##vart = total of roll so far

Set: vart =&#91;when&#93; {\$var1} = {\$var2} &#91;do&#93; {{\$vart}+{\$var3}}&#91;end&#93;
##if doubles are rolled, add var3

Total of {\$vart} ({\$var1},{\$var2},{\$var3}
##Print stuff out for debugging purposes)
```

The variable "vart" is supposed to contain the total of the rolls. Only, the [when] statement doesn't seem to work - it's not comparing var1 and var2 properly, and it's not adding var3 to them if they are equal. Additionally, the output is all messed up, viz:
```Total of  0 (5,5,1

Total of  0 (6,6,3

Total of  0 (2,2,6

Total of  (6,3,2

Total of  (2,3,4

Total of  (6,1,2

Total of  0 (3,3,2

Total of  (6,3,6

Total of  0 (1,1,2

Total of  (1,5,4

Total of  (4,3,2
```

I can't help but feel it's a syntax problem, but I can't figure it out.

• Not sure if it's in the format you wanted, but this code seems to do the trick:
```Table: BashRoll
Set: roll={1d6}
Set: tot=&#91;when&#93;{\$2}&gt;0&#91;do&#93;{{roll}+{\$2}}&#91;else&#93;{roll}&#91;end&#93;
&#91;when&#93;{roll}={\$1}&
&#91;do&#93;{roll} + &#91;@BashRoll with {roll}, {tot}&#93;&
&#91;else&#93;{roll} = {tot}&
&#91;end&#93;
```

The above code returns results like this:
1 + 6 = 7
5 + 5 + 5 + 1 = 16
2 + 5 = 7
6 + 2 = 8
6 + 6 + 4 = 16
6 + 5 = 11