6 ms·
How to program a text adventure in C (2016)
- japanoise 7y agoI like this, very creative! The code generation looks interesting. I'll have to take another look later; can it not be done with the preprocessor?
- franze 7y agoAsk HN: what's a good JS (browser focused) text adventure engine? I see me making a text adventure (adding one mini chapter) each day as a good lockdown project. Note: I might call it "Everything is better in quarantine." The goal would be to (not) go mad.
- kd5bjo 7y agoThe classic engine is Inform, and a quick look in the manual says it can publish to a playable webpage: http://inform7.com/ http://inform7.com/
- indigochill 7y agoInform is definitely the leader in parser fiction and there's been some amazing games made from it (Counterfeit Monkey and Hadean Lands being two of my favorites). I would throw Ink (from Inkle, creators of 80 Days, Steve Jackson's Sorcery!, and Heaven's Vault) in the ring for the choice-driven variant of IF. It also publishes a playable webpage. I made a sort of unconventional portfolio-like page with it here: https://maxsond.github.io/ https://maxsond.github.io/
- tobr 7y agoInk[1] is pretty great, and has a nice editor you can download to get started quickly. I found it really interesting to learn. It is unlike any other language I know, because it deals with such a specific problem. 1: https://www.inklestudios.com/ink/ https://www.inklestudios.com/ink/
- app4soft 7y ago> Ask HN: what's a good JS (browser focused) text adventure engine? Take a look on ISTEAD - Simple Text Adventure Interpreter.[0] It has JS-based version[1,2] and native versions (SDL-based in pure C) for Android[3,4], Windows and Unix-like platforms (including Linux, macOS/iOS, Maemo/MeeGo, Symbian 9.x, various consoles, etc.).[5] Text adventures for INSTEAD could include Lua-scripts (text adventure itself & modules) and various media assets (images, sounds, fonts).[6] There is repo with free games & demos for INSTEAD, which in most cases could be installed directly from INSTEAD clients.[7] [0] https://github.com/instead-hub https://github.com/instead-hub [1] https://github.com/instead-hub/instead-js https://github.com/instead-hub/instead-js [2] http://instead.itch.io/ http://instead.itch.io/ [3] https://github.com/instead-hub/instead-android-ng https://github.com/instead-hub/instead-android-ng [4] https://apt.izzysoft.de/fdroid/index/apk/org.emunix.insteadlauncher?repo=main https://apt.izzysoft.de/fdroid/index/apk/org.emunix.insteadl... [5] https://github.com/instead-hub/instead/releases https://github.com/instead-hub/instead/releases [6] https://instead-hub.github.io/en/#doc https://instead-hub.github.io/en/#doc [7] http://instead-games.ru http://instead-games.ru
- brlewis 7y agoSingle- or multi-player? I'm thinking of figuring out why https://evolvingstory.juliablewis.com/ https://evolvingstory.juliablewis.com/ keeps crashing, cleaning it up and open-sourcing it. Also thinking of rewriting it using a different event system.
- brlewis 7y agoI fixed the logging so should be able to diagnose next time it crashes. Doesn't crash just for me.
- pickdenis 7y agoI'm working on a text adventure that is simply hyperlinked HTML pages with some snippets of JS for state management (just a bunch of localstorage get/put) and fancy effects. It's refreshing to go back to using the "kiddie" tools to make things.
- acdw 7y agoThis is awesome! Do you have the code anywhere? This is the kind of text adventure I want to do but I don't know much js.
- pickdenis 7y agoI haven't put the code up anywhere yet but here is all of the JS (minus some trivial inline scripts): tools.js: https://pastebin.com/p7MQE7KD https://pastebin.com/p7MQE7KD The rest of it is like: <p>You stand before a cave. <p><a href="explore.html">explore the cave</a>
- acdw 7y agoThank you so much!
- BeetleB 7y agoInform and TADS are the two main ones out there. If you want to do the basic stuff, Inform is probably easier. I hear TADS is more powerful if you want to extend the capabilities, though.
- bserfaty 7y agoI suggest to look into https://ifcomp.org/ https://ifcomp.org/ - the annual interactive fiction competition is running for 25 years now and there are some great games and resources over there.
- sn41 7y agoThe greatest text games I have played are Curses! and Anchorhead. Both are immersive and vast. Anchorhead is genuinely scary. There are some pointless puzzles and timed puzzles, but overall, truly worth trying out.
- nvarsj 7y agoThanks for the suggestions! I've never heard of IF before - but I'm a long time MUD / roguelike player. This looks really great.
- tarboreus 7y agoI recommend Counterfeit Monkey, it's the top-rated game on IFDB and I think it deserves that spot. It's also a game that would be impossible to create graphically. https://ifdb.tads.org/viewgame?id=aearuuxv83plclpl https://ifdb.tads.org/viewgame?id=aearuuxv83plclpl
- disqard 7y agoThank you for writing this up!
- gustavorg 7y agoThis programmer, Mr. Ruud Helderman, is like Cool McCool, "Danger is my business!". For example, the parser, function matchParam: OBJECT *obj; par->tag = src; par->distance = *src == '\0' ? distNoObjectSpecified : distUnknownObject; forEachObject(obj) ... The initialization of the obj variable received an obliviate spell. Also function parseAndExecute (). The way he deal with invalid input is, epic: static const COMMAND commands[] = { {executeQuit , "quit"}, {executeLookAround, "look"}, ... } for (cmd = commands; !matchCommand(input, cmd->pattern); cmd++); return (*cmd->function)();
- jstimpfle 7y agoThis is C89 style code where you couldn't declare the loop variables in the for loop, as in "for (OBJECT * obj = ... ". There's no problem with this code. The obj variable is initialized in the forEachObject macro which expands to a for loop. (Pretty damn sure - I haven't actually looked up the definition). The array iteration code is also solid. Seems like a pretty good programmer, judging from the code you cite here at least. While I personally like to put a few assertions just to find my typos quicker, adding additional fluff here is mostly detrimental. The kind of bugs that can happen with this sort of "dangerous" code are the ones that you basically just typos that you catch on the first run. I.e. it's not like there are any rarely occurring edge cases that are unhandled, since the code is extremely straightforward. The "complexity" is very low.
- gustavorg 7y agoOverall I agree with you, my comment is just pointing out that this kind of tricks are dangerous, Cool McCool style, use at your own risk and so. Things you stop doing after your first million bugs fixed.
- jstimpfle 7y agoWell in fact I've tended more and more to this bare kind of coding as I've aged (and hopefully gained experience). Many of the seatbelts (like assertions) I've actually hit at some point or another (so they turned out to be useful in these situations), but on the other hand they allowed me to be more sloppy in my thinking, writing more complicated code, which I feel could be a net loss in productivity. Then again this is just some example code on a website, so it's natural that it has to be done a little more straightforwardly than you would write it in actual practice.
- hendrikhalkow 7y agoAwesome work. Thanks. Looking forward to see more of those vintage games again :)
- anthk 7y agoIt's ok, but inform 6 is better for this.
- alekq 7y agoIt’s great that you read the linked page, because at the introduction he wrote: But then, why this tutorial? Why write an adventure game using a general-purpose programming language? Because doing so can be entertaining, challenging and educational. The programming language C may not be the most obvious choice for writing a text adventure; it's nothing like LISP-based languages like MDL and ZIL. But while writing my own humble text adventure, I learned that C fits the bill quite well.
- yitchelle 7y agoYeah, your comment is OK, but there are better ones in this thread.
- hereisdx 7y agoWow! This tutorial was very fun to follow.