Twine 2.3.8 Harlowe- Inventory Looping

Hello, I am a beginner in Twine working on an interactive fiction. I have made an inventory system that works, however, every time I click the item for its description, return back to the inventory, and then attempt to exit the inventory to resume the main storyline, it loops me back to the inventory.

This is my code for the item:
(if: $rustykey’s isCarried is true) [A (link: “rusty key”)[(set:$selectedItem to $rustykey)(set: $previousPassage to “Inventory”)(goto: “Item Description”)]]

This is my code to exit the inventory:
(link:“Close”)[(goto: $previousPassage)]

All the main storyline passages also have the following code to allow for return:
(set: $previousPassage to “NameofPassage”)

I’m unsure how to fix this issue. Thank you in advance for helping!

Why are you setting $previousPassage to "Inventory" before jumping to the inventory passage? Doesn’t that defeat the entire purpose of the variable? Also, it’s the reason you’re getting stuck in a loop.

I would like to be able to return to the inventory after reading an item’s description, so I set the $previousPassage to "Inventory". While getting rid of that variable would work, I find it a bit inconvenient. Is getting rid of that variable the only way?

Sorry. Yeah, I think I understand what you’re doing now. I think instead of setting $previousPassage to "Inventory", you should just leave that part out. Then in the item description (which I’m going to assuming is using the $previousPassage variable to return to the inventory), I’d just hard code it to return to the inventory.

If the issue is that you want the item description to return to a specific listing (say, either your inventory or a store inventory), I would use a separate variable like $inventoryPassage and set that instead of $previousPassage when jumping to the item description. That way you can use $inventoryPassage to return to the inventory listing and $previousPassage to return to the passage before you entered the inventory.

I have another passage that is titled “Item Description” with the following written inside it:
`(print: $selectedItem’s description)

(link:“Close”)[(goto: $previousPassage)]`

as for the item description, I used this code:
(set: $bag to (datamap:"name", "bag", "description", "An empty olive green messenger bag.", "pickupText", "You picked up the bag.", "isCarried", false))

Since in other passages, I have made it to where you can read the item description in-game and then return to the $previousPassage. If that’s the case, should I do what you suggested and use a separate variable for the “Item Description” passage?

I’m sorry if that didn’t make any sense. Also, thank you for spending the time to help me!

Well… You basically have two options and it depends on how your game is set up.

Option 1 (if you only ever access the item descriptions from your character inventory and not a store or anything): simply remove the (set: $previousPassage to “Inventory”) part before jumping to the description, and in the description change (link:“Close”)[(goto: $previousPassage)] to (link:“Close”)[(goto: "Inventory")]. This should prevent it from redirecting to itself and causing the loop.

Option 2 (if you access the item description from multiple places, like your inventory, shop inventory, found on the ground, etc): Change (set: $previousPassage to “Inventory”) to (set: $inventoryPassage to “NameOfInventoryPassage”) before jumping to the description and change (link:“Close”)[(goto: $previousPassage)] to (link:“Close”)[(goto: $inventoryPassage)] inside the description. This should let you return to the correct inventory passage from a description and also return to the correct previous passage from the inventory.

Okay I tried your options, and it worked out! Thank you so much for your help, tayruh!

1 Like