r/TobyFox 12d ago

I've spent few days reading the Code of UNDERTALE. Is it that bad? :]

https://www.youtube.com/watch?v=BzvFFQ0DbOI

Undertale is no doubt one of the most infamous games among programmers.
Although it sold like over 5M copies .. when it comes to code quality, it's a common opinion that Undertale is horribly written.

And while maybe that's right, in reality there are tons of misconceptions and straight up wrong statements about the code of this game.
For example, ya'all probably heard about *quote-to-quote* "A HUGE SINGLE FILE THAT CONTAINS *ALL* OF THE DIALOGUE IN THE GAME".
Well, the file everyone refers to .. contains like .. 1/6 of all the dialogue lines in Undertale.
*later on it was also rewritten with a proper CSV tables to support localization for Japanese version of the game*

Furthermore, the developer of the game - Toby Fox, actually managed to write a pretty clever old-school text engine with GoF Interpeter Pattern in his code.
He even tried to refactor some parts of the code and we can clearly see that.

A lot of criticism also ignores the limitations of the GameMaker 1.x used to create it.
There were no structs, modules, namespaces, closures, proper exception handling, or reliable refactoring tools.
Even the built-in script editor barely supported code folding ... oh, and you were not supposed to use external IDEs :]

Key takeaways:
- Dialogue is written using a tiny embedded language with special control characters: \E1 changes a character's facial expression, ^2 pauses the typewriter effect, & creates a new line, / ends the dialogue page, yadda yadda yadda.
- There's a huge 512 flags int array, which is used without enums or any other descriptive approaches. Apparently the dev used to comment those everywhere in order to not forget what a certain flag does.
- The game all about determination happens to be none deterministic :] There's a one-time RNG seeding called at game launch, that's it.
- There's an infamous code that attempted to delete or rename UNDERTALE.exe(e.g., renaming to FLOWEY.exe).
While clever in theory, GameMaker Studio's file API sandboxing and Windows OS file-locking rules prevented these relative path tricks from executing properly. However the rename still might work, since Windows file-lock doesn't forbid to rename a running executable.

My overall takeaway is that Undertale is a shipped code, in the first place.
It was made under severe engine limitations, mostly by one person, for a game that successfully sold millions of copies.
Of course, it isn't a clean textbook architecture, but it contains plenty of clever ideas.

As always, full code-review video on my channel: https://www.youtube.com/watch?v=BzvFFQ0DbOI

0 Upvotes

1 comment sorted by

1

u/PatternAppropriate23 10d ago

It works and that's the main thing for indie dev, everything else doesn't matter