Skip to content Skip to footer

How to program a text adventure in C by nivethan

7 Comments

  • Post Author
    serhack_
    Posted April 27, 2025 at 8:32 am

    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 practical with english (includes myself ^-^).

  • Post Author
    metabagel
    Posted April 27, 2025 at 8:37 am

    Section 9 – Code Generation uses awk to parse a text file to generate c files. Very nice.

  • Post Author
    zabzonk
    Posted April 27, 2025 at 11:00 am

    I honestly think that writing an adventure can be best done by first creating an adventure-writing DSL (in C, if you like).

    A few observations on the C code (I didn't read all of it):

    – please, no strtok

    – a little more concentration on the UI, for example not using strcmp to test inputs

    – make all preprocessor definitions be uppercase

    – those conditional operators confused the hell out of me – just use if/else

  • Post Author
    drwu
    Posted April 27, 2025 at 11:35 am

    I thought it was something like LPMud or MudOS [0].

    [0] https://mud.fandom.com/wiki/MudOS

  • Post Author
    parshua
    Posted April 27, 2025 at 1:04 pm

    The best way to implement a text adventure in C would be to implement a simple lisp interpreter in C and then implementing the actual game in a lisp DSL. Lisp lends itself surprisingly well to this, and defining game logic declaratively instead of imperatively is much more intuitive. Here are a few examples:

    [1] http://www.ulisp.com/show?383X

    [2] https://github.com/mswift42/MetalHead

    [3] https://github.com/xlxs4/lisp-spels/blob/main/spel.el

  • Post Author
    HexDecOctBin
    Posted April 27, 2025 at 1:11 pm

    I thought it was going to be something like this: https://github.com/dfremont/glulx-llvm

  • Post Author
    dmbaggett
    Posted April 27, 2025 at 2:22 pm

    Many years ago (circa 1993) I ported the original Colossal Cave adventure by Crowther and Woods to TADS, a language created by Mike Roberts specifically for authoring text adventures. (Colossal Cave just came up recently here.)

    https://ifdb.org/viewgame?id=c896g2rtsope497w

    Graham Nelson ported my port to his Inform language, and Inform is probably your best choice if what you actually want to do is write a (plain text) adventure game.

    If you want to learn C programming, writing a text adventure in C would be a fun learning project! But aside from pedagogy there’s no real reason to write a text adventure in anything other than Inform, TADS, etc. Not only is it much easier to use one of these purpose-built languages, with Inform you get multi-platform compatibility going back to the 8-bit era for free!

    Personally if I had any free time, I’d be more interested in looking at how to use a frontier LLM like llama as an integral part of a text adventure. There was something like this using GPT-2 circulating on here a while back, but it was pretty rough.

    However, it’s clear that if you figured out how to precisely control the LLM so it didn’t produce crazy stuff, you could realize the dream of truly realistic NPCs in these games. Text adventures would seem to be a perfect laboratory for experimenting with this.

Leave a comment

In the Shadows of Innovation”

© 2025 HackTech.info. All Rights Reserved.

Sign Up to Our Newsletter

Be the first to know the latest updates

Whoops, you're not connected to Mailchimp. You need to enter a valid Mailchimp API key.