Howdy, Stranger!

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

Inventory system with Harlowe?

Is there any way to implement an inventory system with Harlowe? It'd be kind of doofy to write a story with 3 different lines for various inventory settings in my story, but I can always write it differently too I suppose.

Or is there a way to change what I'm using in Twine that's compatible with some pre-made inventory script?

I did use the search function but since I just started using Twine everything is pretty much flying over my head. I did read the wiki and look at the inventory stuff on there but I read that code there is just for SugarCube and I'm pretty sure the default Twine is using Harlowe unless I read something wrong.

Comments

  • You are correct that by default the Twine 2 application chooses the Harlowe story format when you create a new story but which story format you actually end up using when you write your story is up to you.
    Just use the Change Story Format option within the menu accessed via clicking on the upward facing arrow in the lower left corner of the Story Map.
  • Oh cool, thank you!

    Now I just need to figure out how to use the inventory code correctly, it just came up with a bunch of boxes... hm.
  • edited October 2015
    I should probably ask here, I have this code:

    So, with a pack on your back full of...

    My most needed essentials!

    Everything I could fit into my pack that I wanted to take with me.

    A bare pack with just some food for the trip, and camping supplies.
    Is it possible to make 3 separate inventories with the code from http://twinery.org/wiki/twine2:add_an_inventory_system or no? I'd like the items to affect the beginning of the adventure and then merge into a later piece but I'm not sure if that's possible.

    Edit: I'm also fiddling with the code for SugarCube for the inventory from that webpage but apparently it's not working correctly, or I'm not using it in the correct way.
  • I checked this post as well http://twinery.org/forum/discussion/2823/simplest-way-to-do-an-inventory-in-twine-2 with no success, twine says the macros are off.
  • Setari wrote: »
    Edit: I'm also fiddling with the code for SugarCube for the inventory from that webpage but apparently it's not working correctly, or I'm not using it in the correct way.
    Where did you place it? It goes in the Story JavaScript.
  • edited October 2015
    Setari wrote: »
    Edit: I'm also fiddling with the code for SugarCube for the inventory from that webpage but apparently it's not working correctly, or I'm not using it in the correct way.
    Where did you place it? It goes in the Story JavaScript.

    I just found the story javascript -_- I was placing it in a new passage window... I'll try it again.

    Alright, now how do I go about making 3 separate ways for a story to progress with 3 separate sets of inventory items?
  • I got it :D!

    Now how to make the inventory list actually show up as a list and not just a line of items... would be nice to get the underscores for the item names to disappear as well.
  • <<if (Stuffed_Rabbit) $inventory>>Go to sleep with your stuffed rabbit<<endif>>

    Is this a correct if statement? I want to make it so an option will show up, if the Stuffed_Rabbit is in the inventory.
  • Setari wrote: »
    <<if (Stuffed_Rabbit) $inventory>>Go to sleep with your stuffed rabbit<<endif>>
    Based on the format of your example I am assuming you are using SugarCube 1, try the following:
    <<if $inventory.contains("Stuffed_Rabbit")>>[[Go to sleep with your stuffed rabbit]]<<endif>>
    
  • Setari wrote: »
    Now how to make the inventory list actually show up as a list and not just a line of items...
    Assuming you mean a list element, the following macro should do what you want:
    macros.invAsList = {
    	handler : function(place, macroName, params, parser) {
    		var markup = "";
    		if (state.active.variables.inventory.length === 0) {
    			markup = "nothing";
    		} else {
    			markup = state.active.variables.inventory.join("</li><li>");
    		}
    		new Wikifier(place, "<ul><li>" + markup + "</li></ul>");
    	}
    };
    
    Just add it to the rest and call it as: <<invAsList>>.

    Setari wrote: »
    would be nice to get the underscores for the item names to disappear as well.
    Don't use them? Seriously, there's no reason to use them in the first place if you don't want to.
  • edited October 2015
    Setari wrote: »
    Now how to make the inventory list actually show up as a list and not just a line of items...
    Assuming you mean a list element, the following macro should do what you want:
    macros.invAsList = {
    	handler : function(place, macroName, params, parser) {
    		var markup = "";
    		if (state.active.variables.inventory.length === 0) {
    			markup = "nothing";
    		} else {
    			markup = state.active.variables.inventory.join("</li><li>");
    		}
    		new Wikifier(place, "<ul><li>" + markup + "</li></ul>");
    	}
    };
    
    Just add it to the rest and call it as: <<invAsList>>.

    Setari wrote: »
    would be nice to get the underscores for the item names to disappear as well.
    Don't use them? Seriously, there's no reason to use them in the first place if you don't want to.

    If I don't use the underscores the whole item name doesn't show up. Like, if I did "Hardened Cheese", it just shows up as "Hardened"?

    Thanks for the help guys, I appreciate it quite a lot. I'm having a lot of fun writing and it's more fun than I've had writing in a long time.
    greyelf wrote: »
    Setari wrote: »
    <<if (Stuffed_Rabbit) $inventory>>Go to sleep with your stuffed rabbit<<endif>>
    Based on the format of your example I am assuming you are using SugarCube 1, try the following:
    <<if $inventory.contains("Stuffed_Rabbit")>>[[Go to sleep with your stuffed rabbit]]<<endif>>
    

    Unfortunately this also throws me an error: Error: <<if>>: bad conditional expression in <<if>> clause: Cannot read property 'contains' of undefined

    Crap, now my other inventory links are messing up as well... buhhhhh. Also yes, I am using SugarCube since that seems to work best for inventory stuff. Also now all of my <<addToInv>> macros are throwing: Error: cannot execute macro <<addToInv>>: Cannot read property 'indexOf' of undefined. (Also I'm literally sitting at my computer waiting for replies all day today lol)
  • Setari wrote: »
    Unfortunately this also throws me an error: Error: <<if>>: bad conditional expression in <<if>> clause: Cannot read property 'contains' of undefined

    Crap, now my other inventory links are messing up as well... buhhhhh. Also yes, I am using SugarCube since that seems to work best for inventory stuff. Also now all of my <<addToInv>> macros are throwing: Error: cannot execute macro <<addToInv>>: Cannot read property 'indexOf' of undefined. (Also I'm literally sitting at my computer waiting for replies all day today lol)
    You probably did not put a call to <<initInv>> in your StoryInit special passage as the instructions note. That is what initializes the inventory, if you don't do that then yes, things are going to be broken.

    Also, what other inventory links?

    Setari wrote: »
    If I don't use the underscores the whole item name doesn't show up. Like, if I did "Hardened Cheese", it just shows up as "Hardened"?
    You must quote item names if they contain spaces. In fact, there's no reason not to quote all item names, really. For example:
    <<addToInv "Stuffed Rabbit">>
    <<addToInv "Hardened Cheese">>
    
    And:
    <<if $inventory.contains("Stuffed Rabbit")>>…
    
  • edited October 2015
    Huh, no. I have <<initInv>> in the beginning, it's been there the whole time, I haven't touched it. I had it in my first passage of my story and it was working fine up until now for some reason. It actually buggered up after I put in your list code, so I just re-pasted it without the list code and it's still being weird.

    I have another section of my story that has multiple items being added to the inventory, more than 3 anyway. The first section I was working on had <<addToInv Bread>> <<addToInv Waterskin>> and <<addToInv Hardened Cheese>>, and adding quotes around them didn't do anything for the errors, but I'll keep that in mind, thanks.

    I added a StoryInit passage before the beginning of my story but that didn't do anything. In fact it gives me a pop-up that says...


    Never mind, it was the StoryInit passage. I'm going to paste the list code in and see what happens. I deleted it because I thought I didn't need it since I had the <<initInv>> in my first page but I guess the StoryInit is important -_-.

    Now the stuffed rabbit thing is back, it shows a connection to the passage, but the link isn't there. Never mind, I had to add the rabbit back to the inventory. Ah yes finally. Thanks much!
  • Setari wrote: »
    Never mind, it was the StoryInit passage. I'm going to paste the list code in and see what happens. I deleted it because I thought I didn't need it since I had the <<initInv>> in my first page but I guess the StoryInit is important -_-.
    The special StoryInit passage is used to do things like initialize your $variable and to add extra features to a story.
    By default SugarCube does not have an inventory system, the code (from the other thread) that you pasted in to the StoryInit passage was adding that feature to your story.
  • edited October 2015
    Sorry to ask more questions, but is there a way to put in a "Go back" link? I tried previous() but that didn't do anything, it just makes a new passage. From twinery.org/wiki/function. I want to be able to have the player to back to the previous window they were just at from checking their inventory.

    Also thank you @greyelf for that explanation.
  • If you are planing on using the SugarCube 1 story format the you should read it's documentation.

    If your inventory is a single passage then you have to basic macro options you can use either the <<back>> macro or the <<return>> macro.
  • Oh awesome, thanks for the documentation. Thanks for the commands as well, I'll input them soon.
Sign In or Register to comment.