10 September 2015

Data Based

I’m trying to make Six Ages easier to create and (hopefully) expand, compared to King of Dragon Pass. One way developers do this is to turn code into data. This can make it much easier to add new content without cracking open the code.

I was about to implement exploration at home, which presented a good opportunity to do this. In King of Dragon Pass when you explore without moving the exploration marker, this code determines what can happen. If we add a new possibility (or have to remove one), the code has to change in several places.

In Six Ages, this is reduced to four lines of code (which actually handles the default case which is not shown for King of Dragon Pass), and this data. New items can be added (or removed) trivially, which is good because I have not yet written all of the new scripts.

Note that the code specific to exotic goods doesn’t exist any longer either. Similar lines are now in scripts, which is a similar push to move code into scripts. (Scripts are still code, but a much more limited form, and much more specific to the game.)

Exploration in arbitrary places also uses data, though it’s a little more complex (and integrated with the map metadata).

While the data-driven approach is easier, it’s worth noting that there can still be bugs caused by data. In this case, listing a script that doesn’t exist would be bad, and there’s no easy way to catch that, since this list is in a Lua file, and the script is in an OSL file. However, it’s easy enough to write a unit test.