Help with creating an inventory

Hi! I’m new-ish to twine, and I am having a difficult time trying to find out how to code this, some help would be greatly appreciated!

I am making a game about exploring a cave. Before you go in, there is a list of 8 items to choose from. You can only choose 3 to take into the cave. Some of these items can be used later on (For example: there is a point where you need ropes to go down, so you can only progress that route if you chose the ropes at the beginning). How can I create a list where you can choose 3 items from the list and they will be stored in the inventory?

If it helps, here is my list of items:

Ropes, Helmet, Batteries, Multitool, Sandwich, Notebook, Mysterious Key, Chalk

Hi,

Maybe you can use the list box three times.
Something like:

Choose item 1
<<listbox "$item1">>
<<option "Ropes">>
<<option "Helmet">>
<<option "Batteries">>
<<option "Multitool">>
<<option "Sandwich">>
<<option "Notebook">>
<<option "Mysterious Key">>
<<option "Chalk">>
<</listbox>>

Choose item 2
<<listbox "$item2">>
<<option "Ropes">>
<<option "Helmet">>
<<option "Batteries">>
<<option "Multitool">>
<<option "Sandwich">>
<<option "Notebook">>
<<option "Mysterious Key">>
<<option "Chalk">>
<</listbox>>

Choose item 3
<<listbox "$item3">>
<<option "Ropes">>
<<option "Helmet">>
<<option "Batteries">>
<<option "Multitool">>
<<option "Sandwich">>
<<option "Notebook">>
<<option "Mysterious Key">>
<<option "Chalk">>
<</listbox>>

<<linkreplace "Inventory">>
You have: $item1, $item2 and $item3 <</linkreplace>>

I’m also new to this so I’m not sure this is the best way, but it seems to work. :slight_smile:

@Caputino Please watch out for the tags under the title of posts :wink:
The OP is using Harlowe and not SugarCube (different methods of coding and formatting the code).

Back to the main question:
You have the (checkbox:) macro, which allows the player to choose items (though you can’t really set a limit on those without extra code). Similarly with the (dropdown:) macro, or the (cycling:) one.
(I’m sure there’s a way to limit options, but I’m leaving this to the experts…)

An easy way could be having three different passages, each where the player can pick one option before moving to the next option (or go to the story). Something along the lines of this:

:: Passage 1
Pick an item
* (link: "Ropes")[(set: $item1 to "rope")(go-to: "Passage 2")]
* (link: "Helmet")[(set: $item1 to "helmet")(go-to: "Passage 2")]
[etc]

:: Passage 2
Pick a second item
(if: $item1 isnot "rope")[* (link: "Ropes")[(set: $item2 to "rope")(go-to: "Passage 3")]]
(if: $item1 isnot "helmet")[* (link: "Helmet")[(set: $item2 to "helmet")(go-to: "Passage 3")]]
[etc]

:: Passage 3
(if: $item1 is "rope" or  $item2 is "rope")[(set _rope to true)]
(if: $item1 is "helmet" or  $item2 is "helmet")[(set _helmet to true)]

Pick a second item
(if: _rope isnot true)[* (link: "Ropes")[(set: $item3 to "rope")(go-to: "Story")]]
(if: _helmet isnot true)[* (link: "Helmet")[(set: $item3 to "helmet")(go-to: "Story")]]
[etc]
2 Likes

Thanks so much, this fixed my issue! I spent 2 hours last night trying to get it to work and whatever magic you did finally got it to work without errors :slight_smile:

1 Like