Using Inform 6 code in Inform 7

If you wanted to – like, really wanted to – could you code in the Inform 6 language in the Inform 7 program? Whether in little chunks in pieces, or making entire games?

Essentially, I’m thinking of teaching people to code by letting them do it in natural language, and then peeling back the systems to do the actual code behind it. Don’t know if it’s a good idea or not yet, but I’m currently trying to poke my nose in everything to see if it’s viable.

You certainly could! This is under “Extensions” in the manual, since extensions are where you usually find I6 inclusions.

But a warning, I7’s I6 code is not a good example of I6 in general. Sort of like how assembly code generated from a high-level language will look strange to an assembly programmer: a weird mix of highly optimized and highly redundant.

Hmm, so a bit less peeling back to see underneath and a lot more “this is like this”.

But to clarify, you could, for example, make a room in I7, then make the same room in I6 in the same window, and therefore “understand” how the two relate to each other? I don’t need to have them open up a separate text editor, or get any separate programs to run it? They just need to know what to code after getting Inform?

So there are two routes you could take there.

There are ways to embed I6 code into I7, but an I6 object declaration in I7 needs a lot of special boilerplate to fit into the modified world model. (For instance, objects are now kept in linked lists as well as two connected trees.)

Alternately, you can build a pure-I6 project in the I7 IDE, but this isn’t yet supported on all platforms.

There’s an additional snag: under the I7 editor, those helpful error messages you get in I7 will be replaced by a message saying, essentially, “something broke that weren’t supposed to break.”

I’m not sure I7 is going to be a good tool for this. It goes from very high-level to very low-level without any stops in between.

I’ll skip over rooms, since (as noted) it’s messy to integrate an I6 room into an I7 project. Consider this simple I7 rule:

When play begins: now the player carries all shiny treasures.

The compiler translates that into the following I6 code. (Lines starting with “!” are comments.)

! When play begins:
[ R_799 ;
    if (debug_rules) DB_Rule(R_799, 799);
    ! [2: now the player carries all shiny treasures]
    Prop_1();
    rfalse;
];

That’s, well, not very educational. You can dig down into the called function Prop_1(), which (ignoring comments) looks like:

    qcy_0 = 0;
    qcn_0 = 0;
    for (x=IK16_First: x: x=x.IK16_Link){
        qcn_0++;
        MoveObject(x,player);
        qcy_0++;
    }
    if (qcy_0 == qcn_0){
    }

This is somewhat better. You can explain to a neophyte that this traverses a linked list and calls a function on each object. But you have to dig up a lot of turf to explain what IK16 is. (An auto-generated linked list of objects of the “shiny treasure” class.)

There’s also the boilerplate about qcy_0 and qcn_0, which do absolutely nothing. The related phrase “if the player carries all shiny treasures…” would do more with those variables. But again, you’d spend a lot of time explaining how Inform treats high-level predicate verbs before that starts to make any sense.

Making a side-by-side mirror game would probably be for the best.

…Well, I mean, not exactly the same, but with the same ideas and concepts and general outputs. It would require them switching between projects, but that’s okay.

And, well, I don’t mind if it isn’t supported as a game, as long as it runs in the original program. Though, I wonder if that’s what you mean – do all versions of Inform, or at least most, have the ability to play I6 coded games in them?

EDIT: Ack, sorry – my internet is acting up, and I didn’t see the newer posts before replying. Hopefully my response wasn’t unintentionally annoying and dismissive!

I chose I7 instead of other game making tools I’m somewhat familiar with (like Stencyl) because there’s a relatively low threshold to understanding the interface to the program, and because it’s easy to make games with. That and I might have naively thought that learning I6 might be easier than trying to cover everything you can possibly try to do with Haxe, even though I’m not familiar enough with either to make that call.

Essentially, if it doesn’t work, it doesn’t work, but I’d like to dig in and learn some things before really making that call. Especially since there are so many ways you can teach things.

But you do get potentially sensible I6 error messages if you click on the Console tab after trying to compile. So if you put this line into a working I7 project:

Include (- phbbbbt; -) after "Definitions.i6t".

you get the internal error message which includes the line “If you are using Inform 6 inclusions, these are the most likely culprits.” Clicking on the “console” tab yields this:

which is indeed the problem.

I had no idea! Thank you for that. yoink!

You can actually insert i6 code in an i7 game, like if theres some function or something you want to force i7 to do. But I don’t think Inform 6 would be a very good platform to teach coding on.

Okay, so it’s sort of possible – just need to figure out how to do it.

Also, I hear that it probably isn't the best place to start in coding.  But, I ask you:  Is [i]any[/i] language a good one to start learning code in?  They're all built to be functional, not learning-friendly.  And I highly doubt there's a way to learn coding while learning the basics of games that isn't jumping both feet in and drowning.

And, well, there's a lot of ways to teach concepts.  I imagine that it's perfectly possible to offset the knowledge load onto Inform 7, instead of leaving it all "Look at this code -- this is a variable, and it does [i]this[/i], and this is a 'if' statement, and it does [i]this[/i], and this a boolean, and it does--"

But, of course, that will require me to figure out how to code in both Inform 6&7 and get [i]others[/i] to do it too, without making it too complicated.  Considering my level of coding skills, that's probably going to take a while.

Inform 7 is a very easy language to read, but not to write. It arguably strongly violates the principle of least surprise by being far from transparent about which natural English constructions it will understand.

A language like Python is widely considered to be a good language to teach programming in. It has a few things which are surprising, but less than many languages, and my feeling is that those surprising things rarely lead to rabbit warrens of further confusion.

1 Like

Yes, but you get very quick feedback on what you did wrong in the program, and there are many ways to try and word things. You already have half the tools in your arsenal, just because you’re writing in plain English and know how to form a sentence. And if you’re following along with a lesson, then you should already have the simpler tools to help you communicate with the program, too.

The thing with inform is that it looks friendly, and will tell you in fairly plain terms that “I don’t understand that statement – it’s like you’re saying one thing is also another thing, and that can’t be true.” Sure, that’s a little… weird, when you’re just saying “Oh, that cord there? If the player mentions that, they’re talking about the keyboard.” or “The Hallway Door is scenery west of the Bedroom.”, but with a little bit of explaining from a teacher, it isn’t that hard to understand at all.

And, I think I didn’t explain myself very well, but you guys are really missing something here – I want to teach people to code while making games. You can’t do that with straight-up Python. I mean, sure, you can use it with Haxe in Stencyl, but with how much you’d need to know to communicate with the program, I’m not totally sure that would help you. You’d literally have to start with the basics in the kiddie pool, instead of leading them out into the water and teaching them how to kick.

And the thing is, confusion? That’s okay. It’s okay to be confused. It’s even better when the teacher anticipates it and builds it into the experience, so that you aren’t suddenly, somewhere down the road, a beginner reading the Inform Designer’s Manual’s little passage on “bitwise operators” and thinking “??? I… only half understood that…? Well, let’s hope that’s never important.”

A lot of people freeze up when they see code, or get discouraged when it takes awhile to produce anything fun. In that sense, Inform 7 is a great language to get people excited about programming: you’re up and running almost immediately, and the syntax is encouraging to beginners who would have no idea where to even start with something like “10 != (int)varx”.

That being said, I have to agree that trying to mix Inform 6 and Inform 7 is a bad idea. Zarf said it well; I’ve been an active coder for ~15 years in everything from PHP to 8-bit assembler, I’ve dug through the underlying I6 numerous times, and I still barely understand what’s going on. Inform 7 has everything you need to teach basic concepts like variables, loops, and conditional logic; introducing I6 doesn’t add much except confusion.

Easing them into other languages via something like Python might be a better choice. (“OK, remember how we said ‘if the bomb counter equals 2’? Here’s how you say that in Python…”)

To be honest, if I was teaching programming to beginners, I’d probably start with an IDE. Microsoft’s Visual Studio essentially lets you choose what language you want to write in. You can literally write an application that has chunks written in C# and other chunks written in something else. Is it complex? Sure it is. But you can teach many important concepts, like OOP. Inform might not be the best starting point. Visual studio is also well documented and has an established support community.

Inform 7 is fantastic and I would never dream of telling someone NOT to teach it to others. However, on the subject of learning environments for coding I would feel remiss if I didn’t bring up Alice or CeeBot, both of which are VERY engaging. Alice has a drag-and-drop interface and encourages exploration, while ceebot uses a c-like syntax to solve puzzles and will make for an easy transition to more traditional languages. I HIGHLY encourage you to check them both out, if you can. They’re quite fun to play with. :slight_smile: