Howdy, Stranger!

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

create inventory using sugarcane format?

Please help. I need to make an inventory for my game.

Comments

  • I was dealing with this the other night. I'm very new to Twine (using 1.4) and wanted to create an inventory and came a cross a few options which seemed (to me) very code-heavy.

    My solution was to create a Special Passage which would appear in the sidebar called 'Inventory'.

    In my StartPassage I 'set' all of my inventory items like this:
    <<set #has_note to "false">>
    <<set #has_lightbulb to "false">>
    <<set #has_key to "false">>
    etc

    Within the Inventory Passage, I listed out all of my 'items' within the game that could be used/handled by the player, like this:

    <<if $has_note is "true" Note obj<<else>><<endif>>
    <<if $has_lightbulb is "true" lightbulb obj<<else>><<endif>>
    <<if $has_key is "true" Key obj<<else>><<endif>>

    What this does, is it will show the link to 'Note' under the 'Inventory' Passage in the Sidebar. If none of the conditions are 'true', it'll be blank. One sort of clunky aspect to this is, it orders the list of items in the order that you put them in the Inventory Passage....so if you have only 2 out of 15 items, there will likely be blank slots in your list. There may be a way around this, but it's beyond me at the moment....one thought is to order them in the same logical order that the Player would encounter/take them. That way, as the Player progresses, the items will appear to be in order that they picked them up. This would also provide a visual cue to the Player that they might have missed something if there is a blank line between the Note and the Key.

    Closing the 'inventory' Passage will create the links to all of your items (Key obj, Note obj, etc)

    Moving on, in my 'Note obj' Passage, I have links to the following Passages:

    Examine
    Take
    Drop
    Use
    Read
    Wear
    and so on, depending on the item...

    Each of those links goes to a specific Passage for that item (Examine Note, Take Note, etc) in which I add conditional statements to check if the item is held, if it's readable, if it's been dropped, etc. and provides a text result. Make sure to include a 'Back' link which takes you to the item's main passage (Note obj).

    It takes me a while to become comfortable with coding and until I really understand the language, I'm leary about dumping a huge string of it into my work. My method, I think, is pretty straight forward, but I'm sure there are others here, much more advanced than I am, that can streamline it for you....but this was my way of handling it.
  • Sorry, to clarify, you'll want to select StoryMenu from the list of Special Passages. In that, add the word 'Inventory'. When you run your game, Inventory will be displayed in the sidebar along with any 'held' items.
Sign In or Register to comment.