Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Basic inventory system in Harlowe

I've been working on an inventory system for Harlowe.

To use it you need to set up 3 variables. $inv is an array of the players inventory. $map is a datamap where the keys are the names of any passage that can store items and the values are arrays. $offstage is an array of items which aren't accessible when the game starts.

Items are just strings. They can be off the form "name" or "name:description". In the latter case the description is shown as a tooltip.

(set: $torch to "Torch:A bright light, perfect for seeing in dark rooms")
(set: $door_key to "Large key:This is the key for your front door")
(set: $small_key to "Small key:It's too small for the front door")
(set: $box to "Small box:It's just a small cardboard box")

(set: $inv to (a: ))
(set: $map to (datamap: "hall", (a: ), "kitchen", (a:), "dining room", (a: $box), "cellar", (a: )))
(set: $offstage to (a: $torch, $small_key, $door_key))

The player's inventory and the contents of the current passage are shown in the footer. This can be blocked by giving a passage the tag 'no-footer'

When a player clicks on an item the default action is to either pick it up or drop it. This can be overridden by making a passage called either take-<name> or drop-<name>.
N.B. This feature depends on accessing the Passages constant. If Harlowe's internals change then this could break. I do it this way because calling (passage:) for a non existent passage results in an error.

If a passage doesn't appear in $map then it's contents is listed as nothing and the player is prevented from dropping anything there.

I've attached a simple game that demonstrates it's usage.

Any comments and suggestions will be appreciated.


  • This is very well done, and useful!! Is there code that also needs to go somewhere to control this? (I am not great with twine, so any drop-in solution is very much appreciated.)
  • Thanks I'm glad it's useful.

    Most of the control code goes in the story's javascript. Though there's some passages that are needed.

    To be honest I'm not terribly experienced with Twine, so I'm not sure of the best way to package code like this as a module to drop in to another story. I've attached a version which just contains the inventory code. You should be able to import it into Twine and then modify it to add your story's code.

    In this version has been modified to handle darkness better.

    Now there's a variable called $lightsources which is an array of any item which can act as a light source.

    If a room is supposed to be dark then give it a tag dark. Also give it two named hooks called lightroom and darkroom.
    [The room is dark, better get out]<darkroom|
    [It's much better with a torch]<lightroom|
    If there's a light source present (either held or in the room) then the lightroom hook is displayed, otherwise it displays the darkroom and shows nothing for the room's item list.

    I've attached a new version of the game to demonstrate it.

    If you have any questions then don't hesitate to ask.
  • This is wonderful and amazing, thank you!
  • edited September 2015
    I'm a bit of a noob; how do you use footers?

    Edit: Actually, if you're going to reply to this, do it here.
  • This looks great. How do I get a copy of it so that I can use it in my game?
    Would you be interested in selling?
  • What would need to be changed in this for it to work with Harlowe 2.0.1? Getting JavaScript and other numerous errors when attempting a conversion.
Sign In or Register to comment.