Exploding Dice

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 =[when] {$var1} = {$var2} [do] {{$vart}+{$var3}}[end]
##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.

Comments

  • 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=[when]{$2}>0[do]{{roll}+{$2}}[else]{roll}[end]
    [when]{roll}={$1}&
    [do]{roll} + [@BashRoll with {roll}, {tot}]&
    [else]{roll} = {tot}&
    [end] 
    

    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

Leave a Comment