On Twitter, Steve Gaynor of Fulbright Games invited people to share their “most embarrassing game dev crimes”. I chuckled my way through a whole bunch of stuff I didn’t quite understand – for project management reasons I understand why it’s hilarious that Baldur’s Gate shipped in debug mode, but not so much for code reasons. 

Then Alex Scokel from Obsidian posted something that hit me right between the eyes:

I hurriedly asked for clarity, horrible memories clutching at my brain. 

After having my first coffee and breakfast, I finally understood what he meant.

My game, Dancing With Myself is a cosy game where you go on a date with yourself, and you can choose the venue, the kind of dinner you want to have, and how you will dress. The full options are:

$venue - Movies, Park, Home  
$dress - Glam, Casual, Relaxed
$dinner - Fast, Fancy, Home

This is a sample of the code that results when you’ve made your choices:

This is not absolutely disastrous code – the game works and if I may say so myself, is fun to play. But it’s possible for the player to be in two time sequences on the same page (in my defence, the idea was that time passes… but I didn’t do it deliberately) and if I want to change something, the whole thing has the potential to fall apart.

A better way to do it, allowing you to make situational tweaks without ruining everything, would be to group the conditions together, with only very tiny inserts for flavour, like so:

<<if $venue is "park" && $dinner is "home" && $dress is "glam">>
(Resulting text for those conditions)
<<endif>>
<<if $venue is "park" && $dinner is "fancy" && $dress is "glam">>
(Resulting text for those conditions)
<<endif>>
<<if $venue is "park" && $dinner is "fast" && $dress is "glam">>
(Resulting text, etc)
<<endif>>

This may seem fussy, but if I want to change some text relating to the fancy dinner, I can quickly find and replace all the “fancy” parts seamlessly, whereas the way I’ve written it in the game makes it much harder to find those parts in all the tightly woven code. It also means I won’t screw up the text in the “fast” and “home” conditions for the players who chose them.

Note that those are only three of the 27 blocks that would result from these combinations! So for a tiny cosy game like this, it’s probably better the way it is. But in a major AAA game, 27 blocks is NOTHING, and gamers will absolutely notice if you fuck up which faction they’re with. As it is, I’m still salty about my Lavellan having to ask “Who is Mythal?” in Dragon Age Inquisition, and I *know* why it’s hard to track that sort of thing.

TLDR: weaving variables makes you feel smart and clever, until you have to make an adjustment that picks the whole macrame owl apart.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s