# D&D Dice Roller

Here I have a program I made to be an all-in-one Dungeons and Dragons 5th Edition (it probably works for other games as well but this is the only one I'm familiar with and the one it was primarily designed for) dice roller for all the common dice sizes as well as a disadvantage and advantage menu for the d20 and custom size support and even a stat roller (4d6 drop the lowest). It comes in two parts, the main program for the user to run and a subprogram designed to reduce the size of the main one by calling it instead of having the same code several times.

"Megumin"→Str5
Lbl 00
ClrHome
Lbl P
Menu("How many sides?","Twelve",12,"Twenty",20,"Custom",C,"One hundred (Percentile)",99,"Stats (4d6 drop lowest)",S,"Page 1",00,"Quit",XX
Lbl 2
randInt(0,6000)→X
If not(X
Then
While not(getKey
Output(1,1,"The coin landed on
Output(2,1,"its side! Flipping again.."
End
ClrHome
Goto 2
End
If X>3000
Then
While not(getKey
End
Else
If X
Then
While not(getKey
Output(1,1,"The coin landed on tails
End
End
End
Goto 00
Lbl 4
4→Y
prgmDICESUB
Goto 00
Lbl 6
6→Y
prgmDICESUB
Goto 00
Lbl 8
8→Y
prgmDICESUB
Goto 00
Lbl 10
10→Y
prgmDICESUB
Goto 00
Lbl 12
12→Y
prgmDICESUB
Goto 00
Lbl 20
Lbl 21
21→Y
prgmDICESUB
Goto 00
Lbl 22
While not(getKey
If max(1/(1+abs(∟NUM-X)))=1
Then
Output(1,1,"You rolled an
Output(1,15,X
Else
Output(1,1,"You rolled a
Output(1,14,X
End
End
Goto 00
Lbl 23
While not(getKey
If max(1/(1+abs(∟NUM-X)))=1
Then
Output(1,1,"You rolled an
Output(1,15,X
Else
Output(1,1,"You rolled a
Output(1,14,X
End
End
Goto 00
Lbl 24
While not(getKey
If max(1/(1+abs(∟NUM-X)))=1
Then
Output(1,1,"You rolled an
Output(1,15,X
Else
Output(1,1,"You rolled a
Output(1,14,X
End
End
Goto 00
Lbl 02
While not(getKey
If max(1/(1+abs(∟NUM-X)))=1
Then
Output(1,1,"You rolled an
Output(1,15,X
Else
Output(1,1,"You rolled a
Output(1,14,X
End
End
Goto 00
Lbl 99
100→Y
prgmDICESUB
Goto 00
Lbl C
DelVar Y
prgmDICESUB
Goto 00
Lbl S
0→dim(∟STATS
For(I,1,6,1
0→dim(∟ROLLS
randInt(1,6,4)→∟ROLLS
1+sum(not(cumSum(∟ROLLS=min(∟ROLLS))))→X
∟ROLLS(X)-min(∟ROLLS)→∟ROLLS(X)
sum(∟ROLLS)→∟STATS(1+dim(∟STATS
End
toString(∟STATS(1))→Str0
For(I,2,6,1
Str0+" "+toString(∟STATS(I))→Str0
End
ClrHome
While not(getKey
Output(5,(int(length(Str0)/2-2)),Str0
End
ClrHome
SetUpEditor
Goto 00
Lbl XX
"Aqua"→Str5
ClrHome
While not(getKey
Output(2,1,"Thank you for using my
Output(3,1,"dice roller!
Output(4,1,"If you have any
Output(5,1,"suggestions I would love
Output(6,1,"To hear them! Email me at
Output(7,1,"              // (here I put a contact email that isn't important here)
Output(8,1,"-Yami
End
ClrHome
"


The DICESUB program is here:

If Str5="Megumin"
Then
SetupEditor ∟NUM
SetupEditor
If not(Y
Input "How many sides? ",Y
randInt(1,Y)→X
ClrHome
While not(getKey
If max(1/(1+abs(∟NUM-X)))=1
Then
Output(1,1,"You rolled an
Output(1,15,X
Else
Output(1,1,"You rolled a
Output(1,14,X
End
End
Return
Else
ClrHome
While not(getKey
Output(3,1,"This program is desgined to
Output(4,1,"run with another program,
Output(5,1,"not on its own.
End
ClrHome
End
Lbl 1
prgmDNDDICE
Lbl 0
"


∟NUM is a list that would be shipped with the program it contains numbers 8, 11, 18, 80, 81, 82, 83, 84, 85, 86, 87, 88, and 89 (so basically any number from 1 to 100 where you would say "an" instead of "a"). Although I could, if it would be better, set that up to be initialized with the program as well.

• Can you format your code properly please. – πάντα ῥεῖ Sep 24 '19 at 19:44
• That's how it's formatted on the calculator itself so I thought it was fine. But I can add indents and whatever else if need be – Himitsu_no_Yami Sep 24 '19 at 19:51
• Without proper indenting your code becomes almost unreadable. – πάντα ῥεῖ Sep 24 '19 at 19:52
• That's fair, I'll do it when I get back to my computer, on my lunch break atm – Himitsu_no_Yami Sep 24 '19 at 19:55
• @pacmaninbw I can certainly expand D&D out. As far as how many dice are rolled per turn it WIDELY varies. Some attacks roll 1 die for determining if they hit or not and 1 for damage while under certain conditions you may role as many as 3 or even 4 to try to hit and I've seen attacks that require 3 or more dice to determine damage and with the possibility of multiple attacks per turn that's not really a question that can be answered. – Himitsu_no_Yami Sep 24 '19 at 22:01