Hi Everyone,
I am using Harlowe in Twine 2.
I am trying to make an inventory that displays items the player picks up. Ideally, I would like the Inventory to be a type of HUD that I can display all the time (with a css fixed position) in every passage. And since it is displayed all the time, I would like the player to have the option of opening and closing the Inventory.
I do not want the inventory to link to any other passage, because that changes the actual passage the person is on, or refreshes the passage they are on, which then changes the value of the variables depending on the passage. So, that is why I need some way of opening and closing without it actually refreshing to another passage or to the same one.
My idea of how to make this work would be to somehow replace a link that says "Open Inventory" with a (display: "Inventory") or with text (as shown below) and then, within the displayed inventory, to have a link that says "Close Inventory" that would replace everything displayed with the orginal "Open Inventory" link.
However, due to my newbiness, I cannot work out how to do this. I am able to get the first part going, by doing something like:
[Open Inventory]<openInventory|
(click-replace: ?openInventory)[ The Inventory Is Now Open
<br/>[Close Inventory]<closeInventory|]
And now I do not know what follows, as I have tried different things to no avail.
I imagine it starts with something like:
(click: ?closeInventory)[...]
And it's the part within the [...] that I can't work out. That part needs to somehow make it go back to the original [Open Inventory] link, without displaying the parsed "The Inventory Is Now Open" text.
Any ideas?
Thanks.
Comments
http://api.jquery.com/toggle/
Also, I would prefer, if it is an option, to use Harlowe code rather than have to resort to JQuery.
If anyone knows how this could be done within Harlowe code, I would appreciate it.
Thanks.
The CSS would look something like this:
And then, in the story JavaScript, you would add something like this:
Try this out:
https://jsfiddle.net/professorsamoff/dz092bnp/
The Inventory passage contains the text description for your inventory. The Open Inventory passage contains the code that will show the Open link as well as the code to display the Inventory passage when the link is clicked. The Close Inventory passage contains the code that will show the Close link, the code to hide the Inventory passage when the link is clicked, and the code to re-show the Open Link. Add the following code to any passage you want to see the Inventory Open/Close option in.
If the above does what you want then you can use CSS to style it all.
timsamoff, thank you for contributing and helping out. Because I am so new to anything to do with programming, I am wanting to concentrate on learning one thing at a time (for now that means focusing on doing things as much as possible withing the Harlowe format).
However, for more advanced people who are into combining the Harlow function with JQuery, I am sure your information will be very helpful.
Thank you!