Live data from Hacker News

How to program a text adventure in C

helderman.github.io

51–56 of 56 posts

Re: How to program a text adventure in C

#51
Some minor notes:

* Text adventures are a case where it is really advantageous to separate the declaration and definition of objects, since cycles are ubiquitous. For C, consider X-macros, tentative definitions (not in C++, sadly), and using the section attribute to make the list implicit (or if you don't want to rely on compiler voodoo, just output the index during another pass).

* It may be useful to distinguish several ways an object belongs to a location: on top of, contained in, held by, equipped by, integral component of, death drop of. Additionally, "has never been moved [by player? by code]" is often desirable to record.

* Backwards ownership is fine for savefiles and initialization, but during runtime it can be useful to cache lists in the other direction. A dict may be worth it in a few places if your adventure gets big enough, but linear search is fine for a long time (and makes e.g. conditional passages easier; you should simply check that every conditional transition is eventually followed by an unconditional one with the same tag. To ensure conditions are handled uniformly, transitions with multiple names should canonicalize first).

* For C statically-allocated arrays within a struct initializer, we've been allowed to write `(T[]){t1, t2, t3}` for a quarter century now. There's no need to name the separate objects.

* It is very useful for the runtime to support the notion of "overlays" - used for things like menus which can use surprisingly similar logic to rooms. Saves should only ever look at the main game layer.

* Relative directions are very interesting, but tricky to add to a game.

What I wish I had was an example of a game that is complete enough to be interesting but not too big, to be used when porting to a new engine.

Re: How to program a text adventure in C

#52

Oh man, I got PTSD (post traumatic strtok disorder) on page two and rage quitted the page. I've lost too many hours to bad stdlib APIs.

Ha ha! The worst thing about PTSD is that you lose the ability to discern legitimate uses of strtok() ever after. Its older variant, post-traumatic goto disorder, is known to have affected prominent computer scientists in the past...

Re: How to program a text adventure in C

#53
post #2

I was wondering: does anybody know if there are any good resources for writing a good text adventure? Any nice tips and tricks? Mainly related to the content. I guess it overlaps with "writing a good novel", but I bet there're some specific advices that can be applied to the text adventure. I wanted to write my text adventure, but I'd offer reader to have multiple options, especially for those who are not really prac…

I've spent the last three years building a game engine specifically to do this, and currently finishing the final draft for the game story I've created to go alongside it.

Happy to share anything you'd find helpful. The big takeaway for me has been, you're going to want to graph out the impact of choices before you write the story. If you know the flow of decisions, then that gives a much clearer structure than trying to write the story first and then create branches off it. I think the reason is that it sets a much tighter scope for the writing doing it that way, whereas if you write the story and then find ways to branch it, the scope for that is functionally infinite.

Got any specific questions?

Re: How to program a text adventure in C

#54
post #49

I think for a lot of people here, the hard part of writing an adventure is not writing the code but coming up with a compelling game with an interesting story and readable text. My advice is that if you want to actually end up with an adventure game that people can actually play, just pick an existing authoring system that looks like it will do sort-of what you want and start writing. I speak from experience when I s…

What are some existing authoring systems that exist for this sort of thing? I know Ren’Py exists for visual novels

Inform is the big one for "GET LAMP"-style parser text adventures although I haven't used it for years.

For choice based text games there is Twine and ink (plus many others).

I personally used ink[0] for a project[1] and it was a joy to use. It comes with an IDE of sorts that makes just sitting down and writing your story easy before you add the bells and whistles.

[0] https://www.inklestudios.com/ink/

[1] https://sheep.horse/voyage_of_the_marigold/

Re: How to program a text adventure in C

#55
post #31

Earlier quoted context omitted.

OO is absolutely the wrong paradigm for interactive fiction. Writing a text adventure has been my favorite way to experiment with a new language for decades now, and I’ve gone down the OO rabbit hole too many times. For this use case, you want something more like an ECS, so that a single entity can be more than one kind of thing at the same time. Consider a talking robotic vehicle. It is an object in the world: the p…

Thanks - I hadn’t heard of ECS before. That expanded my mind :)

That was my reaction when I first came across it.

Re: How to program a text adventure in C

#56
post #2

I was wondering: does anybody know if there are any good resources for writing a good text adventure? Any nice tips and tricks? Mainly related to the content. I guess it overlaps with "writing a good novel", but I bet there're some specific advices that can be applied to the text adventure. I wanted to write my text adventure, but I'd offer reader to have multiple options, especially for those who are not really prac…

Aaron Reed's 50 Years of Text Games[1][2] is a fantastic journey into the history and the possibilities of text-based games. I got the physical book and was surprised to find it as engaging as a novel. Each chapter takes one year between 1971 and 2020 and picks a game from that year to discuss in depth. While it might not help with the writing per se, you might good ideas there (several of the games discussed are in…

This comment got me to purchase this book and bump it to the head of my reading queue. I'm about halfway through it and it's really, really good. I definitely think it can help with writing/design, by showing the breadth of possibilities and how the art has evolved.
Post reply on HN