Effective structuring and layout of code - Inform 7

I am looking for an easy yet effective way to structure my inform source code as mine is getting busy and there seems to be no structure.

Before I go on, I need to place my current code into a structure that I will understand and can easily navigate.

Amy examples or templates I can use to start with?

Short answer: I recommend looking at the source code for Bronze and Slouching Towards Bedlam, which I consider very good examples of code organization.

Longer answer:

The main tool I7 gives you for structuring your code is headings: chapters, sections, all that.

Everyone uses those headings differently, but I recommend looking at the source for some published Inform 7 works to see how their authors did it. A few of these were published by the creators of I7, deliberately intended as examples for new authors: Bronze by Emily Short and The Reliques of Tolti-Aph by Graham Nelson are the largest of them, and show nicely how Emily and Graham like to structure their work.

Apart from the worked examples, Counterfeit Monkey by Emily Short is an absolutely gargantuan piece of I7, and is also open source, but sadly does not have the nicely-formatted website to browse. My own style is heavily influenced by hers, aiming to make the source code as readable as possible, and you can see it at work in Scroll Thief.

For a radically different style, though, Andrew Plotkin and Victor Gijsbers tend to write I7 in a much more “traditional” way (i.e. a way more like you’d code in C or Python or what have you). For example, they tend to name their constants and variables to be clear and concise about what they do, rather than to read fluently in text. And on an organizational level, they both prefer to break large sections of code out into separate extensions, instead of doing everything in one enormous file with headings. Some examples: Hoist Sail for the Heliopause and Home by Andrew Plotkin, Kerkerkruip by Victor Gijsbers et al. (Heliopause doesn’t use the break-into-extensions technique, but Kerkerkruip does.)

Other good examples (where by “good” I mean “influenced my particular style of code organization”) include Blue Lacuna by Aaron Reed and Slouching Towards Bedlam by Star C. Foster and Daniel Ravipinto. The last of these is a great example of a relatively small game (some of the others I’ve recommended here are enormous) with well-structured and well-laid-out code. If you want to look at a more diverse selection, IFDB has a tag for games with I7 source available.

And finally, if you want to see how a whole bunch of different authors structured the same project, Cragne Manor is an I7 work where each room was created by a different author. You can browse the examples and see how each of those authors decided to structure “a single room, sometimes with a puzzle in it”. (One note is that you’ll notice a lot of weird names in the code; that’s because we all had to keep our rooms from interfering with each other, which means putting our names into every item and phrase. You generally don’t need to do that in any other type of project.)

12 Likes

For my first Inform 7 game I came up with this structure for my code.

I used Volumes to indicate major areas.

Screen Shot 2022-07-19 at 9.35.34 AM

I used Books to indicate individual settings, characters, things, and scenes

I used Parts for specific rooms, characters, things (whole outline not shown)

This structure has evolved over time as The Time Machine source code has grown—v1.0 was written for ParserComp 2021 and I am currently on v1.7 working towards a v2.0 release later this year.

2 Likes

Counterfeit Monkey by Emily Short is an absolutely gargantuan piece of I7, and is also open source , but sadly does not have the nicely-formatted website to browse.

The source of release 6 is still available in website form here:
https://tass.neocities.org/source/source.html

3 Likes

Thanks will have a look at all of them

I am trying to use the extension, Threaded Conversation by Chris Conley (v 5/150117) but get the errors as shown in picture.

I did add the following extensions:
Include Plurality by Emily Short.
Include Conversation Builder by Chris Conley.

How do I go about getting this resolved?

There’s a newer version (8/220120) online at the Friends of I7 extensions collection:

I just tried out two of the included examples on I7 6M62, and they work, so the first thing I’d do is to update the extension and see if that resolves the errors.

I updated it to v8 but still get the same errors.
Maybe one of the other extensions needs updates?

Looks like Activity-based Simple Chat by Shadow Wolf is the culprit that does not want to work with TC extension.

Another extension that does not want to work with the TC extension is Plurality by Emily Short.
According to Chris Plurality should be used with TC.
Can I leave it out or do I need a newer version as v9/101223

Yes, as far as I see, Activity-based Simple Chat also defines quips, here:

A chat node has a text called quip.

That causes the conflict with TC’s idea of a quip, which the error above refers to.

I would not try to mix those extensions.

Threaded Conversation is large and quite comprehensive, it should cover most of your needs regarding conversations. I’d recommend to try out each extension in a separate small testing project and then decide which one to use exclusively.
You can try to mix and match behaviour from both extensions, but that’s really an advanced topic.

Thanks, I will go with TC extension for now and test it out in a separate project as you suggested.

I am new at Inform 7 but want a decent conversation system but nothing fancy or difficult.
Do you think TC is the way to go or is there something else you can suggest?

The functionality of Plurality is included in recent versions of Inform 7, so as far as I know, you don’t need to include it.

Thanks, will take it out

Hmm, tricky. TC is powerful, but takes a bit of time to learn and to set up. You can try some of the included examples in a different project and attempt to expand and adapt those, to see whether it fits your game and how easy or difficult you find it.

You could also use Eric Eve’s conversation extensions (find them in this directory), or a subset of them. They work in a similar way and are also powerful, but can be quite complex, too.

In general, it really depends on the style of conversation which you aim for. If multiple-choice menu-based conversation is an option for you, I recommend Hybrid Choices by AW Freyr: extensions/Hybrid Choices.i7x at 9.3 · i7/extensions · GitHub.

Having said all that, you could also consider, just to get started with minimal overhead, to implement simple ask/tell conversation with something like this:

After asking Adam about "bla":
	say "Adam nods and says, 'Indeed.'";

See also the examples in the subsections of chapter 7 of the Recipe Book, like Sybil 1 in RB 7.7.

Thanks, I will look into them all and see what I understand best and later expand to the more difficult ones.

I can just mention I want to try and set up a meeting room scenario where there will be a leader type of and staff members that will discuss a variety of topics about a specific incident.

I still need to figure out how to make something like that interesting, as various members will get tasks to do but can I only complete successfully if they say achieve something before the task - or something like that.

Any ideas from you might help mt thinking to go wild.

Yes, I think we made some headway towards that goal in another thread: Conversation Flow - Inform 7 - #8 by StJohnLimbo

You can set arbitrary flags (truth states / booleans) when the player character or an NPC does or says something, and check those flags in the conversation rules. There are various ways to do that, but in the end it just comes down to a bunch of truth states and if-statements. You can also use the Scene mechanism, as shown in the linked post.

Another small example:

Mission-accomplished is a truth state that varies.

After asking Adam about "mission":
    if mission-accomplished is true:
        say "Adam gives you a thumbs-up sign and says, 'Good job on that mission!'";
    otherwise:
        say "Adam briefs you about the upcoming mission.";

And you would set mission-accomplished to true at some appropriate place inside another action rule, like this:

After taking the secret document:
	now mission-accomplished is true;
	continue the action.