Programming + Absence

Well it’s Friday and I’ve about missed my chance of having a D&D post this week.

I started writing one and I just kept adding more to it. The consequence is no post about Cimmeria this week, but hopefully a giant sized one for next week!

If you’re still craving your weekly D&D post from the GoCorral blog then I still have something for you.

I completed that script I was working on for criticals in Hackmaster on Roll20. Not only that, I completed two more scripts for melee and ranged fumbles in Hackmaster!

They are available for download on GitHub at these locations:
Critical: https://gist.github.com/GoCorral/1297d794e80e78f6238e2bd6c7661e37
Melee Fumble: https://gist.github.com/GoCorral/9240004810d0667c5ac76a083d7a94d3
Ranged Fumble: https://gist.github.com/GoCorral/f0fd318795fdf76643cfd0b2e0908c5f

So if you play Hackmaster using Roll20 and have a Roll20 Pro subscription then these should be pretty valuable to you. If not… you might be able to modify it for use outside of Roll20’s API and still get some fun out of it.

The other announcement of the week is that I will be on vacation the next two weeks.

I’ll do my best to stay constant with updates over that time, but I believe it is inevitable that I’ll be distracted by something in the city in visiting, Nashville.

And when I get back I’ll have a lot to say about the capitol of country music!

Thanks for reading!
-GoCorral

Roll20’s API Scripts

Continuing from my previous post about Roll20, I wanted to talk about how script writing for Roll20 works and the particulars of the script I’m writing.

Roll20 has something called an API (Application Programming Interface) a term that the programmers reading this are already aware of, but one which I had to look up while writing this.

Behind all the fancy jargon I read, an API is a way to write and test programming code.

The simplest “API” is something like Notepad. You can design a program in it, but Notepad won’t run your program or tell you where you messed up.

There are more complicated APIs track syntax errors in your code, color the different key words, point out where you messed up, and even let you test run your code.

Roll20’s API tracks syntax and color codes. It tells you IF you messed up, but not WHERE. So when there is inevitably a problem you get to play hide and seek until you find it.

Every API is designed for a specific programming language. Roll20 uses Javascript.

I didn’t know any Javascript going into this.

I’m familiar with the basics of programming. I’ve taught myself a little bit of Python, I took a course on C in college, and I know a little about Perl and HTML* from various places.
*Not exactly a programming language but I’ll bet that nobody really cares.

To learn the particulars of Javascript I started taking a course on CodeAcademy.

The CodeAcademy course is pretty cool! Nice assisting prompts. A little poor on alternative ways of solving the problems, but that’s actually a good thing for programming courses.

I learned a little about Javascript from that, enough to write the program I wanted to for Roll20.

And what program is that? Something to automatically spit out the results of a critical hit in Hackmaster!

Hackmaster is a game like D&D that I play with my friends sometimes. Hackmaster has a ton of cool rules that make the game quite a bit more fun and shocking than D&D.

One of those rules is what happens when you hit your opponent real good. Depending on your height advantage over your opponent, the weapon you used, and how hard you hit, a special event occurs.

Why do I want a program for that? Well… Take a look.

Critical hit chart comes with lion and everything else you see here.
Critical hit chart comes with lion and everything else you see here.

There are about twenty pages like this that just go on and on.

It’s a bit much to flip through all those pages, cross reference with the different numbers you need, and then trail your finger down the chart to see what happens.

Instead, why not have a program do the work for you?

The program is started when a player uses the Critical Hit macro. Remember how macros can ask for values? That’s all the Critical Hit macro does. No dice are rolled.

The Critical Hit macro asks for seven different values: your size, your opponent’s size, your attack roll, your opponent’s defense roll, your damage roll, your opponent’s armor strength, and the type of weapon you’re using (Crushing, Hacking, or Piercing).

Next comes the script. The script is triggered when the Critical Hit macro is entered.

Nowhere near Matrix levels of code yet.
Nowhere near Matrix levels of code yet.

I looked around on Roll20’s forums and found the skeletons of some other scripts to use for the script to take information out of the Critical Hit macro and use it in the program.

From there, the script rolls a several thousand sided die that represents the location hit by the critical with different sized dice depending on the difference between the attacker’s and the defender’s sizes.

After getting that roll, the script enters a gigantic ~3,000 line long if/else tree that serves in place of the twenty page table. This comes up with a different results based on the location of the blow, how hard the target was hit, and what type of weapon was used.

Finally, the program spits out the result into Roll20’s chat along with some background information to make sure that it worked correctly.

Does the code work? Well, I don’t know yet. I’ve been typing away at it for about a week now and have transferred roughly one fifth of that giant table in the book to the programming script.

Due to how I structured the code, I can’t tell if it works correctly until I finish the whole thing.

Unfortunate, but what can I do at this point?

So here’s hoping that when I’m done in a few weeks and I press that Critical Hit macro button, it runs as smooth as melted chocolate.

If not, then I’ll probably have a blog post to make about code debugging…

-GoCorral

P.S. If you play Hackmaster and are interested in this code I will be posting the completed version of it on the Roll20 forums and the Hackmaster forums once I’ve finished. I’m also planning on doing a similar thing for the Fumble charts for Hackmaster so stay tuned for those as well.

Roll20 and D&D

I’ve mentioned Roll20 in past posts about how my group plays D&D, but I figure it deserves a post all its own.

Roll20 was a Kickstarter project back in 2012. It raised $39,651, well past its goal of $5,000.

Once funded the project team set out to create a free and simple way to play D&D and other roleplaying games online.

They created something that has been dubbed a virtual tabletop (VTT). D&D is normally played at a table, so when you play online everyone sits at their computers around the virtual tabletop.

What does that actually mean though?

First, Roll20 transmits your voice, video, and any typed messages you want to the other people you’re playing with. Continue reading