XaiJu
dicecloud
dicecloud

patreon


Version 2 - New Parser

Some time ago there was a small bug report on version 2's handling of dice rolls: '2d8 + 2' was being factorised as '2(1d8+2)' which might make some kind of sense from an algebra point of view, when it comes to dice rolling, it's not the same thing at all.

Both version 1 and 2 of DiceCloud use an external maths library to parse and calculate things that are entered into formula fields, namely Mathjs. However, an important feature in v2 is the ability to roll dice. The factorisation problem above is just the tip of the iceberg when it comes to issues with trying to patch nondeterministic calculations like dice rolls into a parser and engine not built to handle it.

After shopping around for other parsers and math libraries that would suit what DiceCloud needs, and failing to find anything suitable, I resolved to roll my own.

Introducing DiceCloud's new math parser

The new parser can handle variable substitution, dice rolls, basic math, and some advanced functions. It also has the ability to partially complete some of those steps. For example, if you are defining the damage a weapon does, you need to be able to substitute variables and compute down a certain level, but not actually roll that damage out, but when you attack with the dagger, the damage needs to be rolled.

Rolling out the new parser in place of the old one would probably still break quite a few characters, either through bugs or just not implementing the same functions as the current Mathjs engine. So in order to test it out, I began work on what will become a defining feature of verison 2, and the subject of tomorrow's post, the Log.


More Creators