Howdy, Stranger!

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

Inventory System

Hello all, I've been working on a little horror adventure game here as my first project, and I've been wondering how to create an inventory system in Harlowe. I have seen a few videos with examples and tried to find a discussion that may have what I would need, but still not sure. Most importantly, what is better for an inventory, with things like lighter, lockpick, gun, etc. Would it be best to use a datamap, a dataset with an "isCarried" deal, or should I set up an array? And after that, what is the best way to link to your inventory at any time without having to write the passage link on every passage? Thanks.

Comments

  • Hi!

    I am not good enough yet with arrays and datamaps, so I can't answer your first question.

    I can, perhaps, help with your second one.
    The two most commons ways of displaying an inventory I have seen so far are either to create a sidebar using CSS, or to use passages tagged as header or footer.

    The sidebar method, which can be found at this excellent github page (the whole page has several great tricks), is the following:

    PassageName: Stats / Tag: Header
    <div id="stats">[Save]<save| | [Restore]<restore|
    (click: ?save)[It is being saved(savegame: "A","Test Save")]
    (click: ?restore)[It is being restored(loadgame: "A")]
    (if: $inv's length is 0)[You aren't carrying anything.]
    (else:)[You are carrying: $inv]
    </div>
    

    Story StyleSheet - Orig.
    #stats {
    float: left;
    padding-right: 1em;
    margin-right: 1em;
    border-right: 1px solid black;
    height: 100%;
    }
    

    With the header or footer method, you can put the passage code in a passage tagged either footer or header and it will show up automatically on every page (if you look around in the forums, you'll also find ways to hide the footer or header from specific passages. (See an example here: http://twinery.org/forum/discussion/comment/11966/#Comment_11966)

    I prefer the footer method because it leaves more space at the center of the page for the story text.

    I suggest that you look at this post, if you haven't found it already. there are downloadable examples of a working inventory.
  • I guess if you want to make a small inventory sistem, like "if you dont have the key you cant open the door" or "if you have the gun and bullets the monster dies", using a simple pack of variables at the begining of the story will be enough.

    Visualy if you want to see all inventory in all passages, maybe you can use a table to distribute the story on the left and a small inventary on the right
    <table>
    <tr>
    <td width="80%">...Story...</td>
    <td width="20%">...Inventory...</td>
    </tr>
    </table>
    

    Inside the inventory cell, you can use print instruction to show items as a reminder of what you have.

  • Personally I prefer to use an array to store an inventory. For one thing it's to print out the contents of an array. (print: (set: 1,2,3)) doesn't produce any output.

    You can take or drop items by adding or subtracting an array.
    (link: "pick up the gun")[(set: $inv to $inv + (a: "gun")]
    
    (link: "drop the gun")[(set: $inv to $inv - (a: "gun")]
    

    doing (print: $inv) will display a comma separated list. So a better approach would be something like:
    (print: $inv.join("\n"))
    
    which will print each item on a new line.

    Of course you can get a lot more complicated, depending on the needs of your story.

    For putting a link to the inventory on every page, using a header or footer passage would be the easiest.
  • edited September 2015
    (print: (set: 1,2,3)) doesn't produce any output.
    I think you meant (print: (dataset: 1,2,3)) because what you wrote does produce an output, that output being an error message.
  • Oops, yes, I did mean (dataset: 1,2,3).
  • Thanks for some of the info, it at least got me some help to get started. which I suppose leads to another thing, suppose I want the header to start from a certain point and not from passage one, like the main menu and chapter titles I may not want a header or footer to appear until it reaches a certain passage, anyway to do that? Or at least links to other discussion that seem to have covered that? Thanks
  • The second link included in Melyanna's comment points to one way to do what you wish.
Sign In or Register to comment.