DEV Community

Cover image for Background: Updating a Dice Rolling App
kevhines
kevhines

Posted on

Background: Updating a Dice Rolling App

One of my favorite parts of coding is getting to dig into existing code. Adding functionality. Debugging. Really getting to figure out how a piece of code works. It's been a while since I have done that but recently I got a chance to flex that muscle.

No code in this post, this is just about the project. It's a small one but this will explain what I had to do.

Background: Role Playing Games and Dice

My friends and I casually play different role playing games over slack. If you haven't played role playing games it's kind of like playing pretend, you create a character with certain skills and you interact in a world and with other players to explore that world. Often there are times when you need to bring luck into play (are you able to defeat someone in battle, hack into a computer, recognize a dialect) and when that happens you roll dice.

More Background: Rolling

Slack has a nice app for rolling dice that you can use. You type /roll to start the slash command and then list out the specific dice you want to roll.

So like this:

Image description

This works great. But my friends and I play games that use dice a little differently. So when we started needing dice to roll differently a friend of mine built a custom dice rolling app for Slack to do the job. For example this code rolls percentiles where you can ask it to roll an extra die for a bonus. The bonus die replaces the tens place if it's lower helping you get a low roll. Like this:

Image description

This is a custom app so we aren't using the built in /roll slash command but our own /r slash command. The c signifies that it's using the percentiles roll for this different game. The b signifies roll a bonus die. You can also roll a penalty die with a p. And this app also rolls normal dice like the built in app so we don't need to go back and forth between applications.

Background: a new game

So we started playing a new game. In this game the dice exploded. That means if you rolled a max value, you had to roll the die again and the total was what you rolled. So if you roll a 6 on a 6 sided die you can roll again and if you get a 3 that time your actual roll was a 9. The built in roll app can do this, so we considered going back to that built in app. But after a little playing we realized it doesn't handle multiple rolls the way we wanted it to.

Image description

So it rolls both dice, and explodes them nicely BUT it gives you a total of both dice when we frequently found we wanted two separate subtotals.

So it was decided we should update our custom app. My friend who wrote the code didn't have time to update it but offered to share the javascript code with me so I could update it. In my next post I'll step through how I attacked this fun job.

Top comments (0)