Sugarcane, as noted in the OP title, or SugarCube, as noted in the OP? They are not the same story format and the distinction is important, as the code you linked does not work properly in SugarCube.
I've found a relatively easy way to code an Inventory in Sugarcube. Even though the questions already answered, I'll just tell you what I've figured out on my own anyways.
At the top of every passage the player can access, put <<set $RoomID to InsertPassageTitleHere>>
For instance, if the passage is titled Room1, then <<set $RoomID to "Room1">>
Then, if you want to include the Inventory either in the StoryMenu passage or just in every passage, you can just a link to a passage called Inventory. Then have a link in the inventory passage that says $RoomID
This will return you to the passage you were just in, without having to futz around with passage history or any of that confusing business. I personally like to make very large games and like this one-all solution of "return to the room you just came from"
From there it's a simple matter of just assigning variables to items that go into the inventory and displaying them in the inventory passage. Like, You find an apple <<set $apple += 1>> and then Apples: <<print $apple>>.
Comments
http://strugglingwithtwine.blogspot.ca/2014/03/handling-inventory.html
for anybody that needs it too...
There's a SugarCube-compatible version on these forums if you need it.
At the top of every passage the player can access, put <<set $RoomID to InsertPassageTitleHere>>
For instance, if the passage is titled Room1, then <<set $RoomID to "Room1">>
Then, if you want to include the Inventory either in the StoryMenu passage or just in every passage, you can just a link to a passage called Inventory. Then have a link in the inventory passage that says $RoomID
This will return you to the passage you were just in, without having to futz around with passage history or any of that confusing business. I personally like to make very large games and like this one-all solution of "return to the room you just came from"
From there it's a simple matter of just assigning variables to items that go into the inventory and displaying them in the inventory passage. Like, You find an apple <<set $apple += 1>> and then Apples: <<print $apple>>.