Howdy, Stranger!

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

Twine 2 SugarCube 2.x Inventory System Modifications

Hi there,
I am currently using the inventory system from the Twine Wiki here.
I am currently using SugarCube because I love the responsive css which passes Google's Mobile Friendly Test, and the built-in save/load. For me, they're must-have. I was previously building in Harlowe, and used to have a far better inventory system found here which was better in the sense that it was built to allow passages in which items could be dropped by use of the "drop" tag. Items could be picked up in one passage and then later dropped (and remain to be picked up again) in a different passage.
Currently I have the SugarCube inventory set to allow a drop via going to inventory, clicking on an item, and then in that item's passage a drop option using a click macro, like this:
<span id="Drop">\
<<click "Drop">>\
<<removeFromInv "An Unsigned Note">>\
<<replace "#Drop">>Dropped!<</replace>>\
<span id="output"></span>\
It works, but the trouble is that when you drop an item in a different passage from where you found the item, it removes it from your inventory, but places it back in the passage you picked it up in. To the player this would need to be explained in the story to be some kind of magic in order for it to be plausible.
What would be the easiest way to modify the code from here to better manage items so that they are not "attached" permanently to a given passage and can be picked up and dropped into any passage seamlessly? Attaching my current test story.
Thanks very much in advance for any help!


  • So, I have a few ideas about how to go about this. Problem is, that inventory system is outdated, and designed for sugarcube 1, though it does work in 2. I made my own simple inventory system for sugarcube 2. This is an excellent idea, and I want to implement it into my inventory system. So I guess my question is: how far along are you? I don't want to sell my system too hard, it definitely has issues, and it probably isn't worth rewriting a lot of code for. That said, if you can switch to my system, I can have an extension that does this in a day or two. (I think. Wait for me to deliver before doing a lot of work.)

    I might be able to re-work that extension to work with the wikis inventory system, but that's gonna take a bit.

    I'm hardly objective though, so don't go taking my word for it. Maybe play around with my system a bit first. Someone else might also be able to come up with a simpler solution than what I have planned.
  • Chapel, I came back to my post to basically say never mind, that I found a better system made by Chapel at "Some custom macros and scripts for SugarCube 2". Go figure that you're the one to reply here! Thank you for all your hard work and for sharing your awesome macros, and for suggesting your system here!!! I have your Simple Inventory working well in my story and it fixed some other nagging problems I was having with the old wiki system. That would be super fantastically awesome if you manage to devise a room based pickup/drop functionality for Simple Inventory where items can be sourced in any room, dropped later in any different room, and not still appear in the source room (unless willfully dropped there). I take it you know what I'm getting at. In the meantime, I'm new to SugarCube (but quite familiar with Harlowe) and am unfamiliar to how people work out the non room based inventory systems. What do you suggest? Include a drop option only in the same room an item is available to be picked up in, or just don't allow dropping at all? The thing is, I'd have to find a way in the story to explain how a dropped item magically returns to the source room. I'm trying to exclude magic/supernatural things in my game as it's a wilderness survival/exploration/treasure hunt game. I keep saying room, I mean passage. Forgive, as I do a lot of development in GML.
  • edited July 2017
    Yeah, what I'm working on should allow you to register passages as 'containers', which will each have their own inventory. You'll be able to pick up from passages and drop items into passages as long as they are registered. You can also manipulate these containers from outside the passage, and register certain passages as other passages, so you can make it work in a menu.

    Example non-final code:
    <<placeat 'some passage' 'a sword'>>
    ::some passage
    <<placeitems>> /% lists the items in a place with pick up links %/
    <<register `previous()`>>\ /% drop items into another passage %/
    <<has 'a sword'>>\
        <<link 'drop sword'>>
            <<dropinplace 'a sword'>>

    The original simple inventory just kind of ignored dropping as a rule because of the things you mentioned. It was possible, but that's about it. I'm going to work on making a new list macro that includes these <<dropinplace>> style links for you, which is why we need to have this register macro. Otherwise, we could just say:
    <<has 'a sword'>>\
        <<link 'drop sword'>>
            <<drop 'a sword'>>
            <<placeat `previous()` 'a sword'>>

    But you won't be able to in the linked list.

    It's coming along, but it'll take quite a bit of testing.
    ...What do you suggest?...

    If you have the time, I'd wait for my container system, which should take a couple more days or so. If you don't have the time, I'd honestly just not let players drop things, unless it's extremely important to the mechanics of your game.
  • edited July 2017
    Brilliant! You said in your macros post that you are not a great programmer, but I beg to differ. You have come up with some brilliant code. I will do as you suggest and wait for the containers. Your macros belong on the official Twine wiki, seriously. As far as suggestions, erm, it sounds like you have it covered, the only thing that comes to mind as far as more features would be an additional/optional macro such as <<inventorywithdrop>> that would append "Drop" to items in an inventory list in say, an Inventory passage like so:

    Knife *Drop*
    Axe *Drop*
    Water Bottle *Drop*

    It would drop the items into the last gameplay passage before entering the inventory passage. The complication could be if someone is using it in a footer without a separate Inventory passage, it would have to know to drop the items right there in that passage.
    Perhaps more trouble than it's worth and it's nothing critical or anything but would be a really cool feature.
    Perhaps after this (meaning your containers work), you should rename it to, "Not So Simple Inventory". LOL
    Thanks again Chapel!
  • @AccreditedDesign I'm pretty close to finishing up on this, and I'll be posting it as a standalone extension of the simple inventory on the repository, so it'll be an optional thing. It's a complicated system, so I need to do a lot more testing and I need to write some documentation. I may not get it finished before the forum closes, though I'll try.

    If I don't, just keep an eye on the repository.
Sign In or Register to comment.