0 votes
asked by (710 points)
edited by
I've searched all over for this but can't track down how to have my items appear in an inventory list on the sidebar, or health for that matter etc.

I'm assuming it will be something in the CSS scripts...

Anyone got the way for this to happen? My coding is poor, getting there with a few things, but hard to get the less-known stuff to be revealed...

2 Answers

+1 vote
answered by (530 points)

Are you using sugarcube? If so, you would have to list the items you want in your StoryCaption passage. So make a new passage, title it "StoryCaption" with the caps and all, and whatever you put in that passage will show up in the UI bar. 

 

commented by (710 points)
Yes. Sugar Cube 2.2.1
commented by (710 points)

Thanks.

I am currently using the array method (I think) :

<<set $inventory.itemname = { quantity: x, Internalparts: xx, description: "Item Description" }>>

 

0 votes
answered by (125k points)
Please use the Question Tags to state the name and full version number of the Story Format that you are using, as answers can vary based on this information. t is also helpful if you state if you are using one of the Twine applications.

You also didn't state how you are tracking which items have been found by the Reader.
eg. Individual Boolean based story variables; Item Names stored within an Array story variable; some other means.

None of the Story Formats that come preinstalled with either of the Twine applications have an in-built Inventory System, so you will need to either implement one yourself or use one that someone else has previously implemented (these are story format specific)

Once we know which Story Format and which Inventory System you are using we can then advise you on how to display it within the story format's side-bar.
commented by (710 points)

Hi,

Sugarcube 2.2.1

<<set $inventory.itemname = { quantity: x, Internalparts: xx, description: "Item Description" }>>

 

I also have some dynamic things going on with the items when a gun is fired it reduces the number by one and there's a reload command as well.

commented by (125k points)

As mentioned by @takethel you can use a special passage named StoryCaption to display content in the SugarCube side-bar.

If your $inventory story variable contains defined items like the following

<<set $inventory to {}>>

<<set $inventory.Apple to {
    "quantity"    : 4,
    "description" : "Apple Description"
}>>
<<set $inventory.Banana to {
    "quantity"    : 4,
    "description" : "Banana Description"
}>>

... then you can use the Key & Value format of the range <<for>> macro to loop through each of the defined items like so.

<<for _key, _value range $inventory>>
    /* Display the Key and one or more properties of the Value. *
<</for>>


eg. The following uses an unorder list to display the Key and the Quantity of each item.

<<nobr>>
<ul>
<<for _key, _value range $inventory>>
    <li>_key (_value.quantity)</li>
<</for>>
</ul>
<</nobr>>

... you can use CSS like the following in your Story Stylesheet area to left align the list.

#story-caption ul {
    text-align: left;
}

 

commented by (710 points)
Thank you, this is a great help. It now self-updates on the inventory screen. :)
commented by (710 points)
edited by

One more thing:

<<set $inventory.itemname = { quantity: x, Internalparts: xx, description: "Item Description" }>>

Do you know how I can display the 'Internalparts' amount in the inventory sidebar without it copying? I think I need to nest it?

I've tried this in the StoryCaption:

Inventory:

<<nobr>>
<ul>
<<for _key, _value range $inventory>>
    <li>_key (_value.quantity)</li>
	<li>_key (_value.Internalparts)</li>
<</for>>
</ul>
<</nobr>>

Unfortunately, while it lists 'Internalparts', it does it as a duplicate of the 'itemname' above it, albeit with the correct number for the quantity of 'Internalparts'.

commented by (125k points)
edited by

NOTE: I don't know the data-type of the Internalparts property, so I will assume that it is a primitive one like a String or a number. If it is a more complex data-type (like an Array, a Date, or a Generic Object) then the following solutions will need to be changed based on that data-type.

If you want the Internalparts property to appear in the same list-item (and on the same line) as the Key and quantity property you can do something like the following.

<<nobr>>
<ul>
<<for _key, _value range $inventory>>
    <li>_key (_value.quantity) _value.Internalparts</li>
<</for>>
</ul>
<</nobr>>

... if you want it to apear in the same list-item but on the next line then you can use a <br> (line-break) element to do that.

<<nobr>>
<ul>
<<for _key, _value range $inventory>>
    <li>_key (_value.quantity)<br>_value.Internalparts</li>
<</for>>
</ul>
<</nobr>>

 

commented by (710 points)
Thanks for that, I still need to do some name-changing about but that's a great help.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...