Log In  


I had a bit of time to tinker yesterday. I'm not sure what made me think of the old Infocom text adventures but here we are.

If you're familiar with Text Adventures (or Interactive Fiction) you may know that one of—maybe the—most popular tool for creating them has been the Inform language. The current version is Inform 7 but waaaaay back when I was first learning, it is was Inform 6.

Anyway, I decided to throw together a quick little IF authoring API loosely based on Inform 6. It is by no means complete or particularly advanced. Basically, I followed the first tutorial for the game Heidi from The Inform Beginner's Guide and implemented just enough to make it work. But work it does! Mostly. I think...

The command parser is extremely simple so don't expect too much from it. All commands should be in the form:

verb [noun] [noun]

Where the nouns are optional depending on what you're trying to do. So east or e to walk to the east; take object to pick up an object; and put object target to put an object on/in something else. There are enough verbs, including synonyms, to complete this game and the API even lets you add new ones but don't try to be too creative with your commands. It was mostly just something to do on a Saturday afternoon so I may or may not develop it further.

Cart #jd_heidi_if-3 | 2022-09-28 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
8

The API clocks in at 926 tokens while the example game itself is only 173.

For simplicity's sake here's the code for just the game itself if you're interested in how it works. You can find the original in Appendix B of The Inform Beginner's Guide linked above if you want to see how the two versions compare.

-->8
-- example game: heidi
-- adapted from:
-- 'the inform beginner's guide'
-- https://ifarchive.org/if-archive/infocom/compilers/inform6/manuals/IBG.pdf
--------------------------------

-- defining the title screen
story(
   'heidi',
   "a simple text adventure written\nby roger firth and sonja\nkesserich.\n\nadapted to pico-8 from\nthe inform beginner's guide.\nby jason delaat.\n\n\npress enter to begin.")

-- rooms and objects
before_cottage = object('in front of a cottage')
    description("you stand outside a cottage.\nthe forest stretches east.\n")
    has(light)

forest = object('deep in the forest')
    description("through the dense foliage you\nglimpse a building to the west.\na track heads to the northeast.")
    has(light)

bird = object('baby bird', forest)
    description("too young to fly, the nestling\ntweets helplessly.")
    name('baby', 'bird', 'nestling')

clearing = object('a forest clearing')
    description("a tall sycamore stands in the\nmiddle of this clearing. the\npath winds southwest through the\ntrees.")
    has(light)

nest = object("bird's nest", clearing)
    description("the nest is carefully woven of \ntwigs and moss.\n ")
    name("bird's", 'nest', 'twigs', 'moss')
    has(container|open)

tree = object('tall sycamore tree', clearing)
    description("standing proud in the middle of \n the clearing, the stout tree \n looks easy to climb.\n ")
    name('tall', 'sycamore', 'tree', 'stout', 'proud')
    has(scenery)

top_of_tree = object('at the top of the tree')
    description("you cling precariously to the \ntrunk.")
    has(light)
    each_turn(function(_ENV)
          if contains(branch.contents, nest) then
             print('you win!')
             stop()
          end
    end)

branch = object('wide firm bough', top_of_tree)
    description("it's flat enough to support a \nsmall object.\n ")
    name('wide', 'firm', 'flat', 'bough', 'branch')
    has(static|supporter)

-- connecting the rooms
before_cottage
   :e_to(forest)

forest
   :w_to(before_cottage)
   :ne_to(clearing)

clearing
   :sw_to(forest)
   :u_to(top_of_tree)

top_of_tree
   :d_to(clearing)

-- initialization
function _init()
   location(before_cottage)
   max_carried = 1
end

Walkthrough


This example game is very short with only four rooms and a handful of objects. The goal is to return the baby bird to its nest in the tree. You can only carry one object at a time—as defined by the max_carried variable in the _init() function—but an object inside of something else counts as a single object.

in front of a cottage
--------------------------------
you stand outside a cottage.
the forest stretches east.

> east

deep in the forest
--------------------------------
through the dense foliage you
glimpse a building to the west.
a track heads to the northeast.

you see a baby bird.

> take bird

you take the baby bird.

> ne

a forest clearing
--------------------------------
a tall sycamore stands in the
middle of this clearing. the
path winds southwest through the
trees.

you see a bird's nest.

> put bird nest

you put the baby bird 
in the bird's nest.

> take nest

you take the bird's nest.

> climb

at the top of the tree
--------------------------------
you cling precariously to the 
trunk.

you see a wide firm bough.

> put nest bough

you win!

Some of the words have multiple aliases. Instead of 'bough' you could type 'put nest branch' and that would also work.

8


I can't enter the cottage, @jasondelaat.

Tried 4-different ways.

go cottage
enter cottage
in cottage
open door

@dw817

There isn't an inside of the cottage. I followed the tutorial from The Inform Beginner's Guide verbatim. Well, apart from syntax differences obviously. They didn't write an inside of the cottage so I didn't write an inside of the cottage. It's not a particularly interesting or complete game it's just meant to be an example of how to create the basics of a text adventure.

If you click through to the hidden text in my post you'll see all of the rooms and objects that are defined in the game.


Browsing through the code just now I realized I should probably add 'climb' as an alias for 'up' so I've updated the cart.


There's a bug. Start the game. Head east. Take bird. Type: "PUT BIRD INTO NEST". And it crashes with:

Runtime Error Line 87 Tab 4
Attempt to index local 'target' (a NIL value)


@phil
Ah, thanks. Yeah I should put in a check to make sure it does something sensible with input it doesn't know how to handle. The parser...well probably really shouldn't be called a parser in truth. It's very simple. It doesn't know what to do with 'into': Thinks it's an object but can't find it in the set of objects.

PUT BIRD NEST will work and I'll add that check later when I've got some time so it will at least fail gracefully instead of crash. Thanks for pointing it outd


Hi @jasondelaat:

I had to look inside your code and sure enough you are not covering the cottage. However for the very fact the game had listed the words "cottage" at all.

So then I looked inside the original Inform code to see if there was anything there about it.

And there was, they do handle the cottage after all. You get this:

in_to "It's such a lovely day -- much too nice to go inside."

That right there would've stopped me from trying. :)

Nonetheless it is impressive what you have done here, taking a massive programming language like INFORM and squashing it down to Pico-8.

And for that in your game of Heidi, I applaud you. Definite gold star.


@dw817

Huh. Not sure how I missed that...

Ah! Just went back through the code and that's from the "Heidi Revisited" chapter which adds some additional features and mine was just based on the "original" version which left those out. Fair enough, going in the cottage is a pretty natural thing to try. I was poking around in the code anyway so I've add it in though I don't think I'll bother with the rest of the stuff from that version.

Thanks for the kind words. This is just the barest of bare bones; there are tons of features of Inform that are missing. I may or may not ever get around to adding them but it was a fun little project either way.


Problem, @jasondelaat:

Climbed the tree with the bird in the nest and typed, "Put Nest" and got this error.

Ah, it also died again when I typed, "Put bird" when I was carrying the bird and the nest was on the ground.

Also I could not seem to pick up the nest until I had placed the bird in the nest.

You may include a walkthrough of the game for people like me who keep typing the wrong things. :)


@dw817

> "You may include a walkthrough of the game for people like me who keep typing the wrong things. :)"

Sure, that's a good idea. I've added it to the bottom of the post and I think I've fixed that bug. Thanks for the feedback.


Just tried this on an iPhone, but no obvious way to bring up the device keyboard, despite the keyboard option being enabled. I guess this is a wider option for the mobile player, but could there be a way to enter text, if the keyboard is enabled, please?


@DoctorMikeReddy
Unfortunately I think this is a limitation of the web player on mobile so I don't think there's anything I can do about it myself. And since the devkit modes aren't really intended to be used in actual games like I've done here I don't imagine that's likely to change anytime soon.

I could be wrong though. Maybe I just missed setting a particular flag or something so if anybody knows how to make it work on mobile and it's something I can do, let me know and I'll be more than happy to make the change.



[Please log in to post a comment]