Howdy, Stranger!

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

How can I get my inventory to work? Harlowe.

edited September 2015 in Help! with 2.0
Okay so here's what I got. I have an inventory page and I use the (display:) function to put it's content, and a link to the inventory passage itself. So on any page with the display function I can click the displayed hook to go to the inventory passage. The first problem arose when I tried to use the history function to set a variable to be a link back to the passage you came to the inventory from. (set: $lastvisited to (history:)'s last) Like so. The problem is that you can see the new link when you return to the other page. So after returning you have the inventory items, the link to the inventory, and now a link to the last passage visited. I tried playing around with several things like variables (the problem I found with this was that the inventory page would always update the variable when I needed it to stay changed for the link to work.) The second thing I tried was using a sort of loop (click-replace:) function. I don't want to rule this one out for sure because it is likely I could have just botched it as it was my first time working with that particular function. I know I could make it work with some cheese, but I'd like to have a clean and efficient code set up. Any suggestions would be great.

Comments

  • Without example code it is very difficult to know exactly what you are trying to do, which makes suggesting a solution very hard.
  • Okay I have the "Inventory" passage:
    $weapon
    $totalgold
    Inventory

    (set: $inventory to 1)
    (set: $lastvisited to (history:)'s last)
    (if: $inventory is 1)[ $lastvisited (set: $inventory to 0)]

    So I have the items I want to display and then a link to the inventory page itself that will be displayed along with the items. Then I tried to set up a link back to the passage you came from but I don't want the $lastvisited link to display on the other pages.

    Then from any other page I just have
    (display: "Inventory")

  • edited September 2015
    I'm a bit confused as to why the "Inventory" passage has a link to itself. If they click the link they're just going to see the same information that was already showing.

    If that's intentional, then the way to make sure that the $lastvisited link only shows when the player has clicked the inventory link, is to make it so that link sets the $inventory variable.
    $weapon
    $totalgold
    (set: $lastvisited to (history:)'s last)
    {(if: $inventory is 1)[ [[$lastvisited]] (set: $inventory to 0)]
    (else:)[(link: "Inventory")[(set: $inventory to 1)(goto: "Inventory")]]}
    
    I've also changed the code so that the "Inventory" link only shows when the passage is being displayed from another passage.
  • edited September 2015
    If I am understanding the situation correctly you have two different use-cases:

    a. Show a summary on every page that contains the current weapon, the total amount of gold and a markup link.

    b. A page that displays everything in the player's inventory.

    If this is the case then I would divide your current inventory passage into two passages:

    1. Inventory Summary:
    This passage contains the items from point a and is displayed on every passage, it looks something like the following:
    $weapon
    $totalgold
    [[Inventory->Inventory Detail]]
    
    You may want to use a header tagged passage to (display: "Inventory Summary") passage, that way it is automatically added to every passage and you won't need to add it manually to all your own passages.

    2. Inventory Detail:
    This passage show the inventory in detail and contains a marup link back to the previous passage. It would look something like:
    (link-goto: "Previous", (history:)'s last)
    
    The player's inventory
    
    If you decide to use a header tagged passage then it would look something like:
    (if: (passage:)'s name !== "Inventory Detail")[(display: "Inventory Summary")
    ]
    

    warning:
    Every passage that is navigated to (shown) via a link is added to Harlowe's History sub-system, which is used by the Undo/Redo buttons.
    Because you plan to use a markup link to leave the inventory passage (navigating forward) then the inventory passage is also added to History and therefor if the reader/player uses the Undo button they will navigate backward through it.

    If no variables are being changed by the inventory passage then a better way to leave it would be via the Undo button as that would remove the passage from History.
  • I forgot to attach an Archive file contain an example of the above solution, use Twine's Import From File option to view it.
  • Thanks so much guys.
Sign In or Register to comment.