0 votes
by (2.3k 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
by (870 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. 

 

by (2.3k points)
Yes. Sugar Cube 2.2.1
by (2.3k points)

Thanks.

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

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

 

0 votes
by (159k 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.
by (2.3k 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.

by (159k 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;
}

 

by (2.3k points)
Thank you, this is a great help. It now self-updates on the inventory screen. :)
by (2.3k 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'.

by (159k 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>>

 

by (2.3k points)
Thanks for that, I still need to do some name-changing about but that's a great help.
...