Live data from Hacker News

How to program a text adventure in C (2016)

home.hccnet.nl

1–10 of 36 posts

Re: How to program a text adventure in C (2016)

#3
Ask 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.

Re: How to program a text adventure in C (2016)

#4
post #3

Ask 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.

The classic engine is Inform, and a quick look in the manual says it can publish to a playable webpage: http://inform7.com/

Re: How to program a text adventure in C (2016)

#5
post #4
post #3

Ask 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.

The classic engine is Inform, and a quick look in the manual says it can publish to a playable webpage: http://inform7.com/

Inform 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/

Re: How to program a text adventure in C (2016)

#7
post #3

Ask 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.

Ink[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/

Re: How to program a text adventure in C (2016)

#9
This 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)();

Re: How to program a text adventure in C (2016)

#10

This 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 COMM…

This 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.

Post reply on HN