# Noobest question about inventory code

**URL:** <https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105>\
**Category:** ChoiceScript Help\
**Created:** [July 17, 2018, 6:05am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105 "2018-07-17T06:05:52Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![CypherCarat](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@CypherCarat](https://forum.choiceofgames.com/u/CypherCarat)\
**Post date:** [July 17, 2018, 6:05am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/1 "2018-07-17T06:05:52Z")

</div>

Doing some research on how to set up an inventory system, a question came up.

When people write “comma” like in the example below, what does it mean? Am I supposed to write “comma” or write an actual comma “,”??

```
*temp inventory ""
*temp comma false

*if (milk)
    *set inventory &"Milk"
    *set comma true

```

I know this is probably a very stupid question and I am really sorry if you lose any IQ points just by reading this…

---

<div class="post-metadata">

**Author:** ![Szaal](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/szaal/32/112202_2.png) [@Szaal](https://forum.choiceofgames.com/u/Szaal)\
**Post date:** [July 17, 2018, 6:32am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/2 "2018-07-17T06:32:39Z")

</div>

It’s just a code that gives the comma character to the inventory. So they’ll write down

```
Milk, not-milk, fake-milk, etc.

```

I believe on further reading, you’ll find another code that reads like

```
*if comma
   *set inventory &","
```

---

<div class="post-metadata">

**Author:** ![Metatex](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/metatex/32/63142_2.png) [@Metatex](https://forum.choiceofgames.com/u/Metatex)\
**Post date:** [July 17, 2018, 6:33am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/3 "2018-07-17T06:33:02Z")

</div>

I can’t say I’m 100% sure (because I’ve never used commas in this kind of a scenario) but I think it’s used for placing a comma in the inventory. Like, in typing. It looks as though it is used so that if there is another thing in the inventory, it places a comma down. So you’d use it if you wanted to specifically place a comma down if the string before it had a string after as well, and not place it afterwards.

The reasoning for this is because you can’t put down a comma on all of them, or you would have a comma afterwards that would be out of place.

---

<div class="post-metadata">

**Author:** ![CypherCarat](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@CypherCarat](https://forum.choiceofgames.com/u/CypherCarat)\
**Post date:** [July 17, 2018, 7:00am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/4 "2018-07-17T07:00:56Z")

</div>

So it’s used for making a list of things, right?  
Got it. Thanks!

---

<div class="post-metadata">

**Author:** ![MeltingPenguins](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/meltingpenguins/32/255855_2.png) [@MeltingPenguins](https://forum.choiceofgames.com/u/MeltingPenguins)\
**Post date:** [July 17, 2018, 11:01am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/5 "2018-07-17T11:01:35Z")

</div>

```
INVENTORY
*if (milk)
   @{(inventory =1) Milk|, milk}
*if (eggs)
   @{(inventory =1) Eggs|, eggs}
Etc

```

should work too.

Edit: fixed it. Small logical error on my end.

This needs a

```
*create inventory 0

```

and everytime something is added or taken out a

```
*set inventory +number
Or
*set inventory -number

```

Multireplace is a blessing.

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 17, 2018, 1:52pm UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/6 "2018-07-17T13:52:18Z")

</div>

> [@MeltingPenguins](#):
>
> Multireplace is a blessing.

I guess?

90% of the examples of multireplace I see leave me scratching my head and wondering what advantage it had over the old way. It rarely seems to be more concise, nor much clearer (to me, anyway). But to each their own. 🙂

---

<div class="post-metadata">

**Author:** ![will](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/will/32/132033_2.png) [@will](https://forum.choiceofgames.com/u/will)\
**Post date:** [July 18, 2018, 1:42am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/7 "2018-07-18T01:42:51Z")

</div>

Here’s an example of how multireplace is way better:

You’ve got three options of groceries: apples, milk, and bread.

Some of those nouns are uncountable, and some are countable. Bread uses loaves and bags, milk uses cartons, and apples use a basket filled with a countable number of individual apples. You can’t just substitute out the words apple/milk/bread, especially not if you want your language to sound natural and easy and maintain a sense of narrative flow.

Shitty way, where apples must always be plural and you’re not allowed to specify the container or situation in which they are found:

```
You look in your kitchen and find some bad ${groceries}. You chuck everything out.

```

Old way, where you use `*if` statements to give yourself more freedom to express yourself narratively:

```
You look around your kitchen and find
*if (groceries = "apple")
  a basket of rosy red apples with maggots squirming inside.
  *goto next
*elseif (groceries = "milk")
  a stained carton of expired milk in the fridge.
  *goto next
*else
  a bag of mouldy bread.
  *goto next
*label next
You chuck it all out in the trash.

```

New way (assigning each grocery a number rather than a string, where apple = 1, milk = 2, and bread = 3)

```
You look around your kitchen and find @{groceries+1 |a basket of rosy red apples
with maggots squirming inside|a stained carton of expired milk in the fridge|a
bag of mouldy bread}. You chuck it all out in the trash.

```

I know which one I’d be happiest with using over and over again throughout a project.

---

<div class="post-metadata">

**Author:** ![CypherCarat](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@CypherCarat](https://forum.choiceofgames.com/u/CypherCarat)\
**Post date:** [July 18, 2018, 1:53am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/8 "2018-07-18T01:53:02Z")

</div>

I have two questions:

1. In your old way, can you use the \*elseif more than once if you want to have, for example, 4 options? Been wondering that for a while since I read about it on the website.

2. Regarding multireplace… I don’t really get it. Please bear with me because I’m really new to this. In your example, which piece of text would be displayed? All of them? In that case, what does the +1 do?

---

<div class="post-metadata">

**Author:** ![will](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/will/32/132033_2.png) [@will](https://forum.choiceofgames.com/u/will)\
**Post date:** [July 18, 2018, 2:02am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/9 "2018-07-18T02:02:40Z")

</div>

1. Yes. You have to end with else, though, or else quicktest will throw a fit.
2. Only one, corresponding to their number, separated by |pipes|. The first option is for groceries = 1, which is apple. The second is for groceries = 2, which is milk. Et cetera. You can theoretically go indefinitely but I recommend sticking to just 2-4 options (footnote).

The reason that it’s +1 is because of the aforementioned fit-throwing of quicktest.

I could explain why it’s necessary, but it’s a little bit complicated and annoying, so you’ll just have to trust me. Assign your options starting with 1 (not 0), include the +1 in multireplace, and have your first option technically be null (that’s why there’s a pipe at the start). I’ve found that this is the only combination that works without quicktest chucking a temper tantrum at me. If it ain’t broke …

Basically, with this set-up, quicktest checks to see if the variable is 0. If it is, it doesn’t write anything there, which is totally fine, because your options start at 1, not 0, so your players will always see something written.

(footnote) I have an event where the specific things that a character says can be randomised to give it some variety if you have the same event happen more than once. Six random options for where you wake up and six random options for what your friend says to you. I have to admit that was a bit messy for just one paragraph of flavour text. Don’t be like me. Stick to 2-4 options.

Oh, I forgot, true/false is easier.

```
"Hi honey, I'm home! @{went_to_store I see you got us some groceries!|You forgot the
groceries again, you pathetic [i]swine[/i].}"

```

---

<div class="post-metadata">

**Author:** ![CypherCarat](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@CypherCarat](https://forum.choiceofgames.com/u/CypherCarat)\
**Post date:** [July 18, 2018, 2:41am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/10 "2018-07-18T02:41:47Z")

</div>

To be honest, the “old way” _looks_ a lot easier to me, but I can understand why you’d say multireplace is better. I’ll have to look into that!  
Thank you!

---

<div class="post-metadata">

**Author:** ![Szaal](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/szaal/32/112202_2.png) [@Szaal](https://forum.choiceofgames.com/u/Szaal)\
**Post date:** [July 18, 2018, 4:01am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/11 "2018-07-18T04:01:27Z")

</div>

Psst. This is an _ **inherent, absolute, undeniable** _ advantage the multireplace has over standard `*if/*else/*elseif`.  
'tis a secret, don’t tell anyone 🤫

```
What would you like to order?
*if special
   Today, our special menu is
   *if day = 1
      fried bread.
   *elseif day = 2
      pressurized steam milkfish.
   *elseif day = 3
      special standard-food.
*choice
   #The standard food
      Here you go, a plate of standard food.
   *if special
      #The @{day fried bread|pressurized steam milkfish|special standard-food}.
         Here you go, a
         *if day = 1
            piece of fried bread.
         *elseif day = 2
            pressurized steam milkfish.
         *elseif day = 3
            plate of special standard-food.
```

---

<div class="post-metadata">

**Author:** ![jasonstevanhill](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/jasonstevanhill/32/198375_2.png) [@jasonstevanhill](https://forum.choiceofgames.com/u/jasonstevanhill)\
**Post date:** [July 19, 2018, 10:32pm UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/12 "2018-07-19T22:32:48Z")

</div>

This is an example of how I use it in Vampire/St. Louis:

`You, however, have wiles of your own. You don't even have to go to a room; she sits @{male on your lap|at your side} and laughs at your @{speaks_english jokes.|jokes, even if she doesn't understand your tongue.} You then surprise her by taking a few moments to listen to what it is she has to say. Before long, no one cares that you are necking in the corner. She certainly doesn't.`

I think you’ll end up using this a lot in Stormwright.

---

<div class="post-metadata">

**Author:** ![MeltingPenguins](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/meltingpenguins/32/255855_2.png) [@MeltingPenguins](https://forum.choiceofgames.com/u/MeltingPenguins)\
**Post date:** [July 19, 2018, 10:41pm UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/13 "2018-07-19T22:41:16Z")

</div>

I mostly use it for verbs in my things if the a character uses the plural form of them with their pronouns.

---

<div class="post-metadata">

**Author:** ![Hazel](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/hazel/32/77796_2.png) [@Hazel](https://forum.choiceofgames.com/u/Hazel)\
**Post date:** [July 22, 2018, 9:18am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/14 "2018-07-22T09:18:04Z")

</div>

I put it in just in case I ever felt a burning need to use a verb that ends with a Y.

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [July 22, 2018, 1:17pm UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/15 "2018-07-22T13:17:42Z")

</div>

> [@MeltingPenguins](#):
>
> I mostly use it for verbs in my things if the a character uses the plural form of them with their pronouns.

This I definitely agree is a key benefit of multireplace. (As it happens, I wrote Section 2 of [the wiki on multireplace](http://choicescriptdev.wikia.com/wiki/Multireplace), which describes one approach to this…the way I’d thought was most code efficient, though someone else might well have found a more efficient way, or just something more intuitive for them.)

As for the rest…I can absolutely see the value with some common Booleans, as in Jason’s examples (or e.g. “aristo” or “helot” in my game, where I do indeed expect to use it a lot from now on).

But still, I feel like a whole lot of the examples I see proffered on the forums are more like, well, Section 1 of the Wiki. I look at  
`@{var1 "The dragon is blue"|"The dragon is red."|"The dragon is green."}`  
and think, _We were doing that better with_  
`"The dragon is ${color}."`

I’m half-convinced by Will’s groceries examples, but my own use of similar numeric variables wasn’t designed to lend itself to multireplace. I’ll often be checking a combination of specific values and ranges, e.g.

```choicescript
*if var1 >= 10
  Relationship text.
*elseif var1 >= 4
  Infatuated text.
*elseif var1 = 4
  Friendly text.
*else
  The text hates you.
  *if var1 = 1
     In fact, didn't you try to kill the text that one time?

```

And finally, the longer a multireplace selection gets, the more I feel that I’d be losing the ability to sense-check my own code by using it. By the time we’re at four options, unless they’re very terse (and of course mine often aren’t), I think I’d rather break it onto separate lines than try to parse a super-long single line in the middle of a paragraph. For me, efficiency gains can be outweighed by legibility, and multireplace examples often seem to exchange a little extra efficiency for a major drop in legibility.

But maybe that will become less true as I use it more. 🙂 And of course it may not be an issue at all for others.

---

<div class="post-metadata">

**Author:** ![CypherCarat](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@CypherCarat](https://forum.choiceofgames.com/u/CypherCarat)\
**Post date:** [July 23, 2018, 12:22am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/16 "2018-07-23T00:22:34Z")

</div>

> [@Havenstone](#):
>
> For me, efficiency gains can be outweighed by legibility, and multireplace examples often seem to exchange a little extra efficiency for a major drop in legibility.

I agree with this. My biggest problem with multireplace so far (haven’t attempted it myself, but from the examples I’ve seen) is that it makes the code harder to read for me. Maybe because I’m a baby coder who’s just starting, I don’t know. But still, using a bunch of conditionals on separate lines is a lot easier for me to read because it looks more organized (?) and clear.

---

<div class="post-metadata">

**Author:** ![Szaal](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/szaal/32/112202_2.png) [@Szaal](https://forum.choiceofgames.com/u/Szaal)\
**Post date:** [July 23, 2018, 1:03am UTC](https://forum.choiceofgames.com/t/noobest-question-about-inventory-code/41105/17 "2018-07-23T01:03:56Z")

</div>

> [@CypherCarat](#):
>
> is a lot easier for me to read because it looks more organized (?) and clear.

No no, you’re right. It does indeed reads clearer and more organized. And honestly, now that I think about it, the efficiency gained by using multireplace is like a few bytes freed up from the memory; a measly, insignificant, ignorable gain one might say.

**However,** another benefit of multireplace is the conditional checks.

While normal `*if/*elseif/*else` command allows multiple checks per result, multireplace allows single check to give multiple different results.

* * *

* * *

Just like on my previous example, modified a bit

```choicescript
*if special and (day = 2)
   fried bread
*elseif special and (day = 3)
   special standard food
*else
   standard food

Vs.

*if special
   *if day = 2
      fried bread
   *if day = 3
      special standard food
*else
   standard food

Vs.

*if special
   @{day |fried bread|special standard food}
*else
   standard food
```
