Wednesday, January 29, 2014

Inform 7 for AIF pt. 1: The Logic of I7

Though I'd like to write a tutorial for writing AIF with I7, this starts off as sort of an essay/rant that only relates peripherally to AIF, so bear with me.

Why I Use Inform 7

Inform 7 is a programming system that uses natural language. You can download Inform 7 here.

I've always liked programming but I've never been particularly good at it. I7 is the only programming language I've mastered to a degree (that is, I'm better than the majority of its users, but not quite as good as those people who really get dirty into I6). When I reflect on why, I think it's partly because I'm a language oriented person. Some people can look at E=MC^2 and think, "Oh, energy and matter are the same thing how interesting." Others, like me, need to be illustrated with lavishly complex examples before it "clicks". It's not because I'm less smart (at least, I hope so), but it simply needs to be spelled out for me: "The amount of energy in the universe is equal to the mass of the universe times the speed of light squared." Oh, right.

So, basically, Inform 7 allows me the use of the verbal part of my noggin, because my math side is shriveled and decaying.

Me Whining

It is a general complaint of mine, then, that tutorials about programming aimed at non-programmers rarely actually explain the "logic" of the language. Yes, you are taught to do simple, rather uninteresting tasks that bore you to death, but no one ever explains how things are supposed to fit together. This is what makes TADS tedious to learn, after going through the same tutorial over and over again, learning how to do stuff but never really know the why or how of it. That's why I still can't wrap my head around ADRIFT 5, because the documentation tells me what tasks are and how to use them but not really what a task-oriented approach is.

The Inform 7 documentation, truth be told, is not much better. It took a long time for me to finally "crack" I7, and the day I did, I exclaimed, "Oh! It's just a checklist!" What is a rule-oriented language? It's a language that uses a "checklist" to figure stuff out. An object-oriented language is similar but instead of a checklist it uses labels stuck on the object itself. As soon as I learned this, I became much, much more competent at I7.

In this respect, it seems odd that you'd put something so crucial so far from the front of your documentation. A quick browse through the documentation that the first mention of rules are in section 2.2, but the subject isn't revisited until Chapter 7, and only explained in depth in Chapter 18. As beginner, I never got the sense of how important and flexible rulebooks were and the sort of role they should play. It's easy to become focused on object properties, which I7 frankly handles very inefficiently, compared to rulebooks, which it handles very well. It certainly explains why so many veteran programmers happen to do things "wrong" from my perspective, using lots of memory-intensive properties and relations when a rulebook would do the job better.

The Logic of Inform 7

Everything in I7 boils down to rules. I7 is amazingly efficient at handling rules and not so efficient at handling "things", something TADS is better at. Squeezing performance out of I7 is an exercise in making the best use of rules. Rules rules rules. Rules, dammit, rules.

What is a rule? Unless you skipped the first section (don't blame you) an individual rule is basically a checkbox. A lot of rules are essentially a checklist, we call these checklists "rulebooks".

Imagine before you did anything you consulted a checklist. We are trying to put toast in a toaster. The first check (or rule) might be: do we have the toast? If we don't, we need to pick it up. The second check asks whether we took of the toaster out of its box, the third checks to see if we bothered to plug it in, and so on.

But I7 isn't just a checklist, it's a checklist made from other checklists, with each checklist covering a different aspect of what we want to do. One checklist tells us whether we can do what we want to do. Another checklist tells us how to do it. Another tells us what we should do after. And not only that, the checklists communicate with each other. One checklist can stop another. A checklist can consult another checklist. And on and on.

Let's advance our example into jumping. If we were designing a checklist for jumping, what might it look like?

Is jumping right now logical?
-- Is there space above me?
-- Do I have legs to jump with?
-- Am I standing on a solid surface?
If it is logical, how do I jump?
-- Bend your knees.
-- Push your feet against the ground in a springing action.
-- Allow gravity to pull you back to Earth.

We can think of the underlined components as rulebooks, and each nested component as an individual rule within that rulebook. The first rulebook asks whether we can jump. The second rulebook asks: if I can jump, how do I do that? We can surmise that if the first checklist fails, the second checklist won't even be considered. This is a very important and powerful tool in I7.

The order of the second rulebook is critically important, whereas for the first rulebook it matters little. If we let gravity pull us down first, we'd then jump and never get back on the ground. This is why we divide our rules like this, because while the content of the rules are the exact same the behavior would get all muddled without being organized into rulebooks.

But the true strength of Inform 7 rule system is that we can add new rules. As our world model gets more complicated, we can add new rulebooks, and put rulebooks in our rulebooks, all to decide what happens. For example, let say our world was host to a variety of awful pestilences and nasty things to land on, we can have a checklist like this:

Is jumping right now logical?
-- Is there space above me?
-- Do I have legs to jump with?
-- Am I standing on a solid surface?
-- Do I suffer from (if so, stop):
    -- osteoporosis?
    -- a spinal injury?
    -- Lou Gehrig's Disease?
If it is logical, how do I jump?
-- Bend your knees.
-- Push your feet against the ground in a springing action.
-- Allow gravity to pull you back to Earth.
What are the consequences if I land on:
-- spikes? Severe injury.
-- cushions? No injury.
-- kittens? Severe allergy.

There are a lot of checklists in I7, all consulted for different reasons, though the six most authors will be concerned with are the following:

Before -- What should I do before I even start thinking about jumping?
Instead -- Is there anything that would stop me jumping, or a special circumstance that would cause me to jump in a special way? If so, stop.
Check -- Is it logical for me to jump? If it isn't, stop.
Carry out -- What steps do I take when I jump?
After -- Is there anything special I should after I jump? Perhaps a consequence for jumping in a special circumstance? If so, stop.
Report -- What should I tell you if you jump but nothing interesting happens?

Next time: the anatomy of a rule.

Sunday, January 26, 2014

AIF Toolkit v0.5.1

AIF Toolkit v0.5.0 contained an embarrassing bug that broke the fucking action. The reason I didn't catch it is that my tests are usually between NPCs and NPC sex was working just fine. The new version ought to fix that. It's strongly recommended you update. A special thanks to the anonymous commentator who brought my attention to this.

You can manually patch the extension the following way:

1) Find the following piece of code in Simpler AIF:

Post-action bookkeeping for fucking something with something (this is the define the last fucktool rule):
     now the second noun is the last fucktool.

2) Replace it with the following code:

Post-action bookkeeping for fucking something with something (this is the define the last fucktool rule):
     now the last fucktool is the second noun.

You can also download the new version here.

Monday, January 20, 2014

AIF Toolkit v0.5.0

AIF Toolkit v0.5.0 is released. There are a couple of major changes that break compatibility in a serious way, so it's recommended you save a backup of the prior version of Simpler AIF and Advanced Layered Clothing. Overall, it's worth it. Sex toys and non-standard body parts are now fully supported, in addition to tribadism, frotting, and other things. Read the documentation for more details.

As there are some major changes, I do expect some bugs and I ask that people submit bug reports if they find anything.

A few people have asked me for the extension I used to make Bad Sister with. I have released Adult CYOA with this extension that will allow you to make Bad Sister style games (meaning that it is CYOA with AIF commands). In truth, this extension is a lot better than what I used to make Bad Sister, so you will have a much easier time of it than I did.

To Twine users, you might consider using Adult CYOA. It's only marginally less user friendly, and in exchange, you get a far more flexible parser with tools that are a lot more powerful. You can simulate inventories and add special commands. You can even compile to a browser-friendly interpreter.

In the future, I'm going to try to publish a few tutorials on writing with Adult CYOA. Wait and see.

Anyways, you can download the new version here.

Wednesday, January 8, 2014

Happy New Year Everyone

Hey everyone, thought I might as well tell everyone what's going down on the pipeline.

I wrote a ton last year, only a fraction of it was ever seen by the community at large. Combined altogether, it would have made a rather large AIF game, but the fact it was spread out into three or so incomplete projects makes me cringe a bit. I've got a few projects in the pipeline (I'm also collaborating with someone on something, but I won't say any more about that.)

My primary objective this year is to finish up Version 1 of the AIF Toolkit and to release at least one major game.

So far, people have really like Simpler AIF and I'm happy with that. Version 0.5 is on its way and it will include things like improved handling of non-standard sex organs and anatomies, tribbing/frotting, better support for sex toys and better handling of clothing. It will break compatibility slightly but I'll try and add instructions on upgrading to 0.5.

I also plan on adding a module that will allow for Bad Sister style games. It also allows you to have CYOA segments and interactive segments. It's actually all ready to go except I need to write the documentation and finish the code that lets you use sex commands during CYOA. I'm hoping this will make it very easy for people to write games.

I hope this is a good year for AIF.