Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

Inventory in Sugarcube 2

$
0
0
I'm using Twine 2, Sugarcube 2.18.0 and with my very basic understanding, I can't get an inventory to work.
I copied the code from the twine wiki from the following link:
https://twinery.org/wiki/twine2:add_an_inventory_system
In the Javascipt section, made passage named "StoryMenu" and put [[Inventory]] in it.
Made an Inventory passage and put
<<if $inventory.length == 0>>You do not have any belongings.<<else>>You are carrying:
<<invWithLinks>> <<endif>>
<<back>>
in it.
At my game start I put
<<initInv>>
<<if $inventory.indexOf("An Unsigned Note") == -1>>There is a note here. [[Pick up the note.]]<<endif>>
and made a passage called "Pick up the note." with
<<addToInv "An Unsigned Note">>\
You picked up the note.
<<back>>
in it.

Most of it seems to work, except that it does not add anything to the inventory, which in turn does not let me test if the "There is a note here. Pick up the note." disappears if you have "An Unsigned Note" in your inventory. Over the last 3 days I tried to find an answer on my own, even contemplated to only use variables and if statements to make it work but I just don't like the "dirty" way of doing it. I want it "future proof" if ever want to make another game that requires an inventory. I really spent enough time on it, for a feature that was not really needed or planed for my game and I would really appreciate if someone could point out what I am doing wrong.

Also, since don't know anything about java: Is it possible that you can make the first letter after a dash (-) uppercase? So it will not correct "Mary-Ann" to "Mary-ann"? With the current code it always auto corrects to lowercase:
<<set name to $name.trim()>>\
<<set $name to $name.toLowerCase()>>\
<<set $n to $name.charAt(0).toUpperCase()>>\
<<set $name to $name.slice(1)>>\
<<set $name to $n + $name>>\

Viewing all articles
Browse latest Browse all 1844

Trending Articles