Game Design, Programming and running a one-man games business…

Anatomy of a rare, and weird heisenbug in Democracy 4

Heisenbugs are bugs in code which seem to go away, or change when you look at them in a debugger. They are the worst possible bugs, because they actively resist being found, or even observed by the coder responsible. Any kind of bug that can be reproduced on a developer’s machine, in their development environment can easily be analyzed, stepped through and reasoned with. But heisenbugs are a nightmare. I just (I think) fixed one, and certainly fixed A bug, even if not this one. I thought you might enjoy the process…

First some background. Democracy 4 is the fourth and latest in my series of political strategy games. They are text and diagram heavy, with a properly unique user interface, in 2D, and all of the code is custom, with a custom engine originally coded by me, with a unicode text implementation and vector rendering system coded by jeff from stargazy studios. This means all of the UI elements you take for granted in middleware you use, were custom coded by us. In this case, the bug is my fault, in code written by me. Here is a screenshot:

Then key thing that matters there is the text block under ‘food stamps. This is a policy screen in the game, and that text is the description. Depending on the length of the description (partly influenced by the language you play in), and the screen resolution, it might be that all the text fits in the available space, or it does not. That means sometimes there is a scrollbar to the right of that text, and sometimes its not there. As you would imagine, the scrollbar works just like any windows scrollbar. That means it responds to mousewheels, and also clicks, on the top and bottom buttons (very small) for example.

…anyway…

VERY rarely. And ONLY when I was playing the game outside the debugger, and only in very arcane sets of circumstances that seemed totally utterly random… screens like this (but not just this one) would occasionally not let me click on some elements in the interface. They would not respond at all… BUT… that block of text would scroll upwards, like it was being scrolled through. It was like completely unrelated events (clicking somewhere else) activated a scroll function on a user element I was nowhere near.

This was of course, absolutely infuriating, because it was REALLY rare. And the times I tried crazily to reproduce it in the debugbuild, or even in the release build, but launched from Visual C++, it would not happen. And there were NO reliable steps to reproduce. In fact, even quitting a screen when it DID happen, and then returning to that screen would make it go away.

What the hell?

After a LOT of time, I realized two interesting things. Firstly, when it happened, the game DID make the click sound associated with a mouse click (so the game IS realizing I clicked somewhere) and the scrolling only happened with text inside a specific UI element called a GUI_TextContainer. Although I did not realize it at the time, it was also the case that it ONLY happened where that text container did NOT have a visible scroll bar.

The clue to the bug lies in a closeup of the scrollbars used:

Like all such bars, there is a clickable ‘scrollup’ button, a draggable bar, with above/below page up/down regions, and a clickable down scroll button.

When I create a new GUI_TextContainer, I created a new GUI_ScrollingWindow, which is a container with all of those elements in side. Like any child element, I added it to the Text Container object with AddChild() to ensure it responds correctly and is processed blah blah. Thjn, later when the textwindow is initialized with its position, and the relevant translated text, I do a lot of calculating to work out if that text *is* going to fit in the available space. If not, I set the scrollbar in the correct position on the right, and make a note that the text does not fit (sets BFits to false). Then later, when drawing this UI element, I could skip out a lot of nonsense I don’t need if the text fits, and render it simply as a word-wrapped string. If It does NOT fit, I then drew the scrollbar, and the text in a different way, cropping the text render to the space given the scroll position and so on, blah blah.

All of this sounds reasonable. But it was a big mistake.

I was correctly NOT drawing the scrollbar if it was not needed (why bother! the text fits!) but I had pre-emptively added it as a child of the window anyway. Worse still, I had never initialized the position of the scrollbar and its sub-components AT ALL. This means that in debug / release-from-the-development-environment, all of the relevant variables in that window were getting set to zero, But in a live ‘customer’ environment, the initial positions of those subcomponents could be ANYTHING.

So what could happen, really rarely, is that the ‘scroll up’ or ‘page up’ parts of the scrollbar, might have coordinates like -32054,-5128,27140,41543. In this case, those clickable elements filled the whole screen… but were INVISIBLE. Thus, I have a huge UI mess-up, but I cannot see it, because my ‘quick and easy bath’ that checked BFits, doesn’t draw it.

So very rarely, I create a screen with an invisible scroll up button that fills the entire screen, and happily responds to every click with a scroll-up command. It even nicely plays the button click sound. Luckily, these buttons do not handle keys, so the escape key still quits that whole screen, and the next time it gets created, I’m probably lucky and the invisible bar has moved somewhere harmless.

I’ve changed the code now, to be efficient so that I do not even THINK about creating this scrollbar until I need it, and otherwise its NULL. I also make sure to safely delete it before creating it, in case somehow I go mad and initialize the same text container twice with different blocks of text. I could also have fixed it by initializing the position of a scrollbar safely to 0,0,0,0, but I also like the neatness of ensuring I don’t have a pointless orphan UI element at any point.

This was a classic dumb error. I added an element when I shouldn’t have, and its member variables were not safe. My own dumb slackness. I document it clearly to illustrate how the weird unrelatedness of a bug ‘clicking down here, scrolls text up there. sometimes. only in German, on a Wednesday etc…’ eventually makes total sense.

Hundreds of thousands of people have played probably over a million hours of the game, with this bug in it. No code is bug free, but if you do things right, the ones left in are pretty arcane.

Voting Systems DLC for Democracy 4

I don’t think I’ve even officially announced that I am doing this, so any games journalists reading this can consider this an announcement I guess :D. I am working on an expansion pack for my political strategy game Democracy 4, and that expansion pack will be called…

Democracy 4: Voting Systems

As you can clearly guess, its an expansion that is focused on the way people vote, and on how you campaign in the election. Its mostly a features, rather than just content expansion, so it includes new policies, but also a bunch of changes to expand on that part of the game associated with the election campaign and the voting. Here is a rundown of all of the new stuff I’m working on:

New Policies

There are a whole bunch of these, including the minimum voting age, a scary ‘maximum voting age’, rules on corporate donations to parties, and state funding of parties, bans or limits on donations, robo-calls and TV ads during the campaign. There are 11 new policies in total. Some of these will already be in place at the appropriate setting, like the minimum voting age, for all countries, and the compulsory vote policy for Australia

Campaign Focus

A year before the election, you will need to pick a single metric, from a pre-defined list, to be the main metric that will feature in your campaign literature and campaign advertising in general. This is the game equivalent of Clintons ‘Its the economy, stupid’ or Tony Blairs ‘Tough on crime, tough on the causes of crime!’. The idea here is that you pick a metric that you think makes you look good, and hope that nothing turns bad with regards to that metric before election day. Once chosen, a new effect will run from that metric, to all the voters. If you improve the metric…great but if for whatever reason it turns bad, there will be a big negative impact.

Once the campaign focus is chosen, its highlighted with a small red icon in the corner of that metric on the main UI, and also highlighted when viewing that metrics details. Once the election is over, assuming you won…the focus goes away.

Voting Systems

The majority of countries in the game use some sort of ‘proportional representation‘, but some use a constituency based or electoral-college system, that is called ‘first past the post‘. The two systems can give very different results, and you can now pass a law to change from one to the other. Proportional representation results in higher turnout, and can favor smaller parties in 3 party countries. You can expect to see more coalitions in countries with proportional representation.

Campaign Style

Immediately before the election, you have the option of tweaking how your campaign is run. You have a slider that lets you select anything from an optimistic, safe and respectable campaign, right through to a scandalously cheeky dirty-tricks style negative campaign that tries to smear your opponent. The extent to which such a campaign works (rather than backfires) is partly dependent on how trustworthy you are in the eyes of the electorate. Depending on the outcome, the effectiveness of your campaign spending can be increased or reduced.

Better Polling Data

A new option will appear on the polls screen. Currently, in the base game, this simply shows the voting intention of all voters, along with the current approval rating for all voters. This will get an extra option, via checkbox, that lets you change this to see the likely voters, rather than the whole electorate. Some people are more likely to vote than others, so viewing likely voters gives a better impression of the actual result. Toggling between the two will also allow you to see if you should take action to increase (or cynically maybe decrease) turnout in the election.

…All of this is coded, and implemented, and in the DLC that I am currently testing. Testing an expansion pack can be a pretty long process, because I need to ensure it all works, that its balanced and that it adds something cool to the game. I then also need to get all of the text for the new content translated into every language we currently support (which is a lot…and Arabic is coming too!).

This will likely take me a few weeks, and then I’ll be getting it into the hands of the Democracy 4 players! Hopefully all of these additions sound quite cool. Its certainly been interesting working on it. I know that a lot of people think I should add states/constituencies to the game, and support a whole bunch of different types of PR voting systems. I understand the appeal, but its likely overcomplex for a game like this. Most people are not *that* interested in the pros and cons of different types of PR, and certainly very few people know the political characteristics of all 50 US states AND all 650 UK constituencies and so on…for every country :D

The eventual erosion of the middlemen

Recently I had to communicate with a landowner about a potential site to build a solar farm, because yes, thats what I do some times. Because the discussion might involve some technical aspects I am not aware of, I went through the company I have a relationship with to build these things. However, on the other side of the negotiation, the landowner also went through a third party. A land agent.

Many of you have experienced this if you try to move house, and buy a new property. You want to sell your old house, and buy a new one. But you need to talk to an estate agent (or realtor in the US?) to communicate with the people you are selling your old house to, and talk to a second estate agent to buy the house you want. They are also talking to a third middleman to buy their property…

The problems here are massive, not least the fact that all of these people expect some percentage of the cost, but they also are SLOW, because frankly, they are quite happy where they live. Whats the hurry? And also their incentives are misaligned. An estate agent might take 1.2% of the sale price when they sell your home. You get the other 98.8%. If the house costs $300k, They can expect to make $3,600. If they can get a 5% better price by negotiating harder, they get $180 more. But you would get $15,000 more. Of course they don’t give anywhere close to a damn about you getting a good deal as you do…

Of course thats just when things are going ok, and the actual objectives are aligned. So you want to sell your house, and the estate agent has an incentive to sell it too. In theory, the estate agent is on your side. A bit. But a lot of the time, we deal with middlemen who are NOT on our side.

If you have ever bought a non-tesla car, you have probably gone to a ‘dealership’. There is a good reason that the slang term ‘stealership’ exists in the US. These are middlemen. Their job is not to help you buy a car, their job is to trick you into paying as much money as possible for whatever they want to sell you, and their loyalty is firmly to themselves. You may THINK you know what model car you want, but if they get better commission on another model, then they will say ANYTHING THEY LIKE to try and trick you into changing to that one.

And don’t for one minute think once you pick a car its over. They will then try to sell you add-ons, extras, extended warrantees and other crap. The last time my wife bought a (diesel) car, I remember having to warn the dealer that if he even mentioned a single more thing related to optional add-ons we didn’t ask for, we would walk out and abandon the deal. (she is more polite than me).

As you may know, the stupidly-fast-growing car company Tesla, has no dealerships. They have ‘showrooms’ where you can see the cars, but these are rare, the staff there do not push you to buy, and in fact if you decide you do want to buy, they will basically tell you to use the website. They also do not get commission. The cars have long waiting lists. I’ve been waiting for my new one since October, and its expected by the end of this year. A years wait to buy a car direct from the manufacturer…

Dealerships used to serve a purpose. Information. In 1970, if you wanted to buy a new ford, you would have to go to a showroom, and have the staff answer questions like ‘how fast does it go?’ ‘what colors are available’? and ‘how much luggage space is there?’

LOL.

Its 2022, and ever car company has a whizzbang website with videos, multiple images, and online configurators where you can see every possible permutation of how your ideal car would look. Every possible statistic is listed. You could also go to YouTube and watch any of the thousands of youtube channels about cars, where impartial real-world tests are carried out and you get to see exactly how each car handles each situation. You can now be ludicrously informed about a car before even leaving your sofa.The information gap between you and the car dealership has shrunk, maybe even reversed. I suspect I know more about the Tesla model Y (my next car) than most of their staff. They have to know about the whole range, whereas I can be laser focused on the car I want. The entire reason for car dealerships to exist is now gone.

The same is true for estate agents. The role of the estate agent is basically to show you what houses are for sale… and maneg the process of buying the one you want (or selling yours). There IS some hassle involving lawyers and mortgage providers here, but actually not very much. The vast majority of the time, estate agents are doing one of two things.

  • Showing you around a house
  • Playing telephone tag or email with buyers and sellers

The first of these is patronizing as hell. They open a door to the bathroom and say “this is the bathroom”. I know, I’ve seen one before. We even have one in our own house. Thanks buddy. There is an argument that they need to be there to keep an eye on you, sure, but the extent to which they need to facilitate viewings is now vastly lower than before.

Before we bought this house 12 years ago, we drove a LONG way here to look at lots of options. When we got there, it turned out one of them was right next to a sewage treatment building. The estate agent had not mentioned this, because they are bastards. These days, in 2022, we can all easily browse google street view, and check out dozens of photos, maybe even videos of any potential house and its surroundings before bothering to go ‘visit’ any which we can now tell are non-starters before we even get in the front door.

Again, information has destroyed the vast majority of the power of the middle-man/woman.

In my own file of computer games, this is also happening, but we are currently only half way there. The original business model was bricks-and-mortar stores, where you walk in, pick a video game from a shelf and buy it. That horribly exploitative model collapsed with the internet and buying online. For a few years, people tended toi sell online from their own website, paying very little commission. 5% would be considered a lot, as you are basically just paying credit card fees and chargeback/fraud protection, plus some absolutely trivial disk storage and bandwidth costs. This is still an option today, and you can buy Democracy 4 semi-direct from me, at 5% commission here:

Most people do not do this, because there are super-popular online stores now like Steam, Epic and GoG and Humble. In the mobile realm, this is totally controlled (many would say illegally) by apple and google. The middlemen who facilitate buying something from someone went from physical stores to online, but did not go away. The commission they take dropped from over 60% down to 30%, buts its still very much there.

I actually believe this may be changing. The EU and the US are both currently looking into legislation to combat monopoly practices by tech giants which no doubt include the idea that they can take 30% of every transaction. Personally I believe this is way overdue. The same forces that have started to crumble the car dealership module will eventually force their way into the online realm too.

Hit hard by digital sales, GameStop is looking to close up to 150 stores  this year - The Verge

When I started selling video games online in 1997, one top tip people had was to put your phone number and address on your website (yikes). People would NEVER hand over their credit card over the interwebs, but they would feel much safer if they could use a telephone to speak to a human. People also HAD to have the option of having the product snail-mailed to them on a physical CD as a ‘backup’ in case your fly-by-night website went bust and they had no way to get the game again! For what its worth, My company has been selling online since 1997. Steam was announced in 2002, 5 years later., I’m still here.

Many of the ‘value-add features that game-store-middlemen provide have ben eroded over time. They provide the bandwidth to re-download the game! This costs virtually nothing these days, especially for smaller indie games. They provide an online message board for the games players! but so does reddit, facebook, and a billion other places. They provide hosting for trailers and videos about the game! But so does youtube…

There is definite *value* to customers in having a single place where they know they can find all this, but increasingly the actual ‘location’ of information on the internet is becoming moot. I no longer have to care what the web address of a specific site is (and I remember the days when we laboriously typed h t t p : // on front of every address…). Since virtual assistants became a thing, I can now just yell ALEXA, READ ME REVIEWS OF GAME X, and it can do it. Are those reviews from site X or Y? I don’t care.

Its an interesting time to be in selling games online. There was a brief period of stability where it was established, firmly, that games got sold through the apple store, the google play store, or through steam. That was it. But this may now be changing. Its likely changing in other industries too.

Middlemen need to be absolutely sure they are providing some value that is not just ‘information’. Information is everywhere, available to everyone, trivially, all the time. There is still value in curation, and convenience, but its eroding, and its probably not going to hold its value for much longer.