Random coding advice: Avoid Duplication

A lot of code I see from new coders shows a thought process like this:

— I’ve got a bunch of matches the player can burn
— after a match is burned, it is moved to a container for used matches; that way I can count how many matches have been burned by writing “the number of matches in the used matched depository”.
— after writing that enough times, I get tired of the verbosity and want to be able just to write “the number of burned matches”. Okay, I’ll also give the matches a “burned” property when I use them up!

Now the burning code looks something like this:

 Instead of burning something with a match:
     [other stuff];
     move the second noun to the used match depository;
     now the second noun is burned.

and other places in the code uses both “number of matches in the used matches depository” and “number of burned matches” to refer to (what the author hopes is) the same information.

This is asking for trouble. Sooner or later you’ll move the object but not set the flag, or change the way the multi-process destruction procedure happens in one place and not in the other. As soon as you do, there will be bugs.

So here’s the advice:

Do not put the same information into your world model twice.

Continue reading “Random coding advice: Avoid Duplication”

Inform 7 Extension “Recorded Endings”

Coming out of my fiddling with Alabaster is an extension for multiple-ending games. Designed for Glulx only (because it uses external files), it keeps track of all the endings the player has found and allows him to review them with an ENDINGS command during the final question.

I’ve occasionally kicked around the idea of a similar extension for games that rely on a fixed set of randomized starting parameters (like the “When in Rome” games, or “Act of Murder”). The idea would be that an external file would record which starting parameters the player had already solved and avoid giving him the same scenario again before he had worked through all of the options. But it is hard to come up with a general syntax for this. Hrm.

Inform build out

Inform build 5Z71 is now out, hosted on a new website, which features, among other things, a new section on education with Inform and reports from teachers in the field; a new introductory screencast by Aaron Reed showing off some of the features of the IDE and how to get your game started; and a revised handling of the extensions allowing authors to view extension documentation online before downloading.

Introductory (live) Inform workshop?

I got some email this morning from a middle-school teacher who is interested in using Inform in the classroom, but wants some help in getting up to speed with it. Here’s the text of the request:

Do you know of any sources I could check out that might offer workshops,
conferences, etc. (especially in the summer), that I might be able to
attend and get some training on the program? Is there anybody out there
doing that, or is it mainly a “learn it for yourself” situation? I’d
really like to get in a small group setting with an expert who can take
me through the basics while we’re in the same room.

I was about to write back and say, no, no one does that — but it occurs to me that I don’t know that for certain. Does anyone out here know of such a thing?

Geekiness

Using my proud newfound .dot skillz plus a lot of hand editing, have drawn a chart of Inform 7’s rulebook structure, including the rules and activities that Inform runs through in a given turn. (Procedural rules, which can happen any time, and some activities for managing output, which are ubiquitous, do not show up in the chart. So e.g. there is no chart entry for “printing the name of something”. But most things are in there.)

(PDF on clickthrough. It’s kind of big, I warn you.)

rules-chart-tiny

The plan is to refine this a bit and put it on the Inform documents page with future releases, if it is found to be helpful.