# Inventory Code Help

**URL:** <https://forum.choiceofgames.com/t/inventory-code-help/9253>\
**Category:** ChoiceScript Help\
**Created:** [May 8, 2015, 9:50am UTC](https://forum.choiceofgames.com/t/inventory-code-help/9253 "2015-05-08T09:50:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuvalbab](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/yuvalbab/32/16784_2.png) [@Yuvalbab](https://forum.choiceofgames.com/u/Yuvalbab)\
**Post date:** [May 8, 2015, 9:50am UTC](https://forum.choiceofgames.com/t/inventory-code-help/9253/1 "2015-05-08T09:50:41Z")

</div>

Hey everybody, I try making an inventory in my choicescript\_stats.txt for a long time and cant get it right. everything’s fine and there is not error messege; except when i actually choose the item the inventory remains empty. Here’s the code:

\*if (silenced\_pistol)  
\*set inventory &“Silenced Pistol”  
\*set comma true  
\*if (sleepdarts)  
\*if comma  
\*set inventory &", "  
\*set comma true  
\*set inventory &“Sleep Darts”  
\*if (taser\_gun)  
\*if comma  
\*set inventory &", "  
\*set comma true  
\*set inventory &“Taser Gun”  
\*if (throwing\_knives)  
\*if comma  
\*set inventory &", "  
\*set comma true  
\*set inventory &“Throwing Knives”

Inventory: ${inventory}

---

<div class="post-metadata">

**Author:** ![FoxalypticWorld](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/foxalypticworld/32/264486_2.png) [@FoxalypticWorld](https://forum.choiceofgames.com/u/FoxalypticWorld)\
**Post date:** [May 8, 2015, 3:27pm UTC](https://forum.choiceofgames.com/t/inventory-code-help/9253/2 "2015-05-08T15:27:43Z")

</div>

Should look like this:

```
*temp inventory
*set inventory " "
*temp comma
*if (silenced_pistol)
    *if comma
        *set inventory &", "
    *set inventory &"Silenced Pistol"
    *set comma true
*if (sleepdarts)
    *if comma
        *set inventory &", "
    *set inventory &"Sleep Darts"
    *set comma true
*if (taser_gun)
    *if comma
        *set inventory &", "
    *set inventory &"Taser Gun"
    *set comma true
*if (throwing_knives)
    *if comma
        *set inventory &", "
     *set inventory &"Throwing Knives"
     *set comma true

Inventory: ${inventory}
```

Not sure if you had the temp variables at the top of your choicescript\_stats.txt. It seems like you forgot the \*if comma statement on your silenced pistol.

---

<div class="post-metadata">

**Author:** ![Sashira](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/sashira/32/2899_2.png) [@Sashira](https://forum.choiceofgames.com/u/Sashira)\
**Post date:** [May 10, 2015, 10:00am UTC](https://forum.choiceofgames.com/t/inventory-code-help/9253/3 "2015-05-10T10:00:30Z")

</div>

If you hate concatenation, like me, you can keep a running count of inventory slots.

Whenever you get another thing, set a variable number\_of\_items +1. That can then assign it to a slot:

```
(You get the silenced pistol)
*set number_of_items +1
*set new_item "silenced pistol"
*gosub set_item_slot

```

(onward with the code)

(Here is the item slot subcode)

```
*label set_item_slot
*if number_of_items=7
   *set item7 new_item
*return

```

In the stat screen you now know how many commas to use:

```
[b]Inventory:[/b]
*if number_of_items=7
   ${item1}, ${item2}, ${item3}, ${item4}, ${item5}, ${item6}, ${item7}

```

This is also a way to keep slots straight if you’re doing a visual interface of inventory spaces.

---

<div class="post-metadata">

**Author:** ![Yuvalbab](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/yuvalbab/32/16784_2.png) [@Yuvalbab](https://forum.choiceofgames.com/u/Yuvalbab)\
**Post date:** [August 20, 2015, 6:52pm UTC](https://forum.choiceofgames.com/t/inventory-code-help/9253/4 "2015-08-20T18:52:10Z")

</div>

Worked, Thanks very much
