Live data from Hacker News

How to program a text adventure in C (2016)

home.hccnet.nl

21–30 of 36 posts

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

#21
post #20

Earlier quoted context omitted.

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 her…

> The array iteration code is also solid. Shouldn't there be a NULL at the end of the array and do a null check in the iteration?

I think the last array entry {executeNoMatch , "A?"} will match on any string (and print the fallback "I don't know how to VERB" message), so it's impossible to fall off the end of the array. If you wanted to use a more defensive-programming style then you could add a sentinel of some kind and assert that you never hit it.

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

#22

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…

How do you feel qualified to critique someone else's C code, even publicly on Hacker News ? You seem to have basic problems with understanding how a macro (in this case forEachObject) works.

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

#23
post #17

It's ok, but inform 6 is better for this.

It’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.

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

#24
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.

I'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.

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

#25

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…

You see similar code to his unconditional executeNoMatch at the end of the table in table based code all the time. Additionally forEachObject is a macro that immediately initializes a variable. For projects like this the code is completely fine. I'm not sure what is particularly dangerous about this code for a small to medium size project.

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

#26

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…

You have people literally defending uncommented, unclear code in your replies.

There are phases programmers go through. One phase occurs about after 10 years of professional programming. I call this the "no mercy" phase, where these newly-minted senior programmers think defensive programming is for noobs, and scrunch their C code down to the fewest number of lines and characters. And when someone objects, the reply is, paraphrased (as seen in the replies): "You're just not as good a programmer as me." Sadly, it takes another 10 years for this arrogance to dissipate.

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

#27

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…

You have people literally defending uncommented, unclear code in your replies. There are phases programmers go through. One phase occurs about after 10 years of professional programming. I call this the "no mercy" phase, where these newly-minted senior programmers think defensive programming is for noobs, and scrunch their C code down to the fewest number of lines and characters. And when someone objects, the reply i…

If you mean me, you're right in that I've been working with C in varying capacity for just about 10 years (Not that I believe that "years" is a good unit to measure experience). On the other hand, I miss from your comment what exactly is wrong with my argumentation, and I feel that the arrogant comment is not mine but yours (assuming you have 20 years or more).

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

#28

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…

You have people literally defending uncommented, unclear code in your replies. There are phases programmers go through. One phase occurs about after 10 years of professional programming. I call this the "no mercy" phase, where these newly-minted senior programmers think defensive programming is for noobs, and scrunch their C code down to the fewest number of lines and characters. And when someone objects, the reply i…

Most legacy code is this way unfortunately. The actual techniques employed by the "called out" code are not uncommon. I don't think that people are defending the lack of clarity but rather what the code is doing itself. It could be written more clearly, though one could argue that the lengthy series of articles does just that. Maybe it's an exercise for you to write it how you want.

Have you taken a look at some major C codebases? It's not justification but an appeal to authority seems pretty unnecessary :)

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

#29
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.

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

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

#30
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.

I'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.

This 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.
Post reply on HN