A Different Kind of Coding Amnesty

I was inspired to post this thread by a recent Tweet I saw about Balatro:

Balatro source code has an epic 4717 file card.lua with all the game logic spelled out in gargantuan if/else stacks


And a similar one for Undertale:

After I learnt about Undertale Switch Cases I realized that there are only two kinds of developers: The ones that laugh at long switch cases, and the ones that just ship Games of the Year


Especially as I consider games as complex as Social Democracy, I’d love to hear from folks in the community about perhaps sketchy things you’ve done with code just to get a game out the door in working condition.


I think the jury is still out, regarding the parkour system in the I Am Prey beta. My excessive use of macros was either a necessary evil of refactoring, or a horrific and explosive lapse of brain function. :woman_shrugging:

For months, it felt icky to write, but the alternatives would have been an un-refectored hellscape of bugs, so… :sweat_smile:


Any game (and software I worked on on my own in general) that has gotten to that kind of state I have either rewritten or abandoned, because that sounds just unworkable.

E.g. the original sin of my first android app was “REST APIs sound easy, I think I’ll do the HTTP requests and response parsing myself”. That app had a rewrite for 1.0, using libraries for the API, reducing the code size (and bugs) my a huge amount.

I think the jury is still out, regarding the parkour system in the I Am Prey beta. My excessive use of macros was either a necessary evil of refactoring, or a horrific and explosive lapse of brain function. :woman_shrugging:

Also depends on the language and how well you encapsulate it. E.g. big Rust libraries have their own macros that do certain things, and it’s just an accepted standard.


Oh man, so many! Probably the two that I am most ashamed/proudest of are:

  • at one point in Eleusinian Miseries (an Inform game) I needed to get one every turn rule to fire before another, except I hadn’t yet mustered up the enthusiasm to read the section of the docs on rule books (or I might not have yet understood that that’s where I should have been looking?). I had read the bit of the docs where it tells you that in general more specific rules evaluate before less-specific ones but warns you that it’s a bad idea to rely on that; damn the torpedoes, I thought, and larded up one of the rules with a bunch of extra always-satisfied conditionals (if the player is yourself, if the scenery object is in the room where it always is…)

  • There’s a sailing race in Sting, another Inform game, that’s actually better coded than it could be (I rewrote much of the core logic with weeks before the deadline so fewer variables were hard-coded and I could sorta try to balance the thing without manually rewriting a bunch of code) but there’s an event system that’s meant to simulate unexpected stuff which wound up being one giant mess of spaghetti code (I think like two or three hundred lines?), with like six level deep conditionals and lots of copy-pasted text that was a pain to edit consistently. In retrospect I can see how it would have been way easier to break it up, alas.


I’ve never met a problem I couldn’t gate with yet another one-off boolean.


In Loose Ends, every “major scene” (scenes that make time advance) has some code at the beginning that checks if it’s possible to enter that scene. If it’s not, it doesn’t advance time, and kicks you back to the hub. For example, the morgue closes at 2am, so if it’s past that time you need to wait for the next night to go examine the body.

Except toward the end, we decided to add chapter headings to those scenes. And those headings have to print before you enter the scene…and shouldn’t print if you’re just going to get kicked back to the hub without being able to do anything.

So all that code is actually duplicated, once to kick you out after entering the scene, and once to decide whether to print the chapter heading or not. This is an enormous source of bugs waiting to happen, but we didn’t have time to do it better.


Have you even seen Disco Elysium’s variable flag system? It’s wild :joy:


I’d be curious to know how many active qualities are in Fallen London. I’m sure they wouldn’t ever show a complete list but it’d be interesting as all get-out.


I hope this was said in jest. There’s always crappy code in every project, but your project has a better chance of success if you minimize it.


Here’s an example of amazing programming: NASA’s Voyager 1 Resumes Sending Engineering Updates to Earth. I do not aspire to this level of quality.


To be fair, space engineering just has a ridiculous standard of quality and endurance (but for good reason). Though one of my life dreams is to have my code running on something that’s in space, but that probably won’t happen.


I don’t see anything wrong with having the whole thing as state-based driven game, though? In fact, I’ve designed several. Good for beginner writer/game designer/coder, IMHO.

I’ll have something in this nature coming up, hopefully sometime soon!

Of course, I’m the kind of crazy guy who can implement even normal programs as one gargantuan switch case. Just one goto, I swear! :rofl:


No, but there’s no reason that a state-driven game has to be coded with any switch statements at all.

You can use if-else ladder if you like. In fact Scott Adams game use that structure, as exemplified by ScottKit toolkit.

The daemon is done via a series of ifs. The user action is done via a series of if-else. This is done over switch-case when the condition is more sophisticated than what can be expressed via a number.

Switch statement’s aren’t bad though, gotos are. Many languages even have special support for control flow checking in switch statements when using enums, so you can make sure all cases are handled. It’s nice if you break out each case into it’s own function though.


I’m not sure I would say that if else and switch statements are bad - they are way easier to debug and less evil than lots of other things you could be doing. (Polymorphism, templates, overloading, etc etc)


Folks, I think we might be getting away from the concept of amnesty :slight_smile:


Sorry I’m not sharing my embarrassing coding experiences on the Internet. But I will say I’m less interested in stories about how something got duck taped together than how you spent 6 months trying to implement a general system for simulating phase transitions or something which ended up completely failing.

Make a new thread then? This thread is specifically about the bashed together, duct taped stuff


Fair enough, though I think we have different opinions about how conversations work. My comments are a direct response to the ideas in this thread.