Noobest question about inventory code

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…

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 &","

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.

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

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

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
*set inventory -number

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. :slight_smile:


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
  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.

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?

  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].}"

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!

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

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.
   #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.

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.


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


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

This I definitely agree is a key benefit of multireplace. (As it happens, I wrote Section 2 of the wiki on 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.

*if var1  >= 10
  Relationship text.
*elseif var1  >= 4
  Infatuated text.
*elseif var1  = 4
  Friendly text.
  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. :slight_smile: And of course it may not be an issue at all for others.


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.

1 Like

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

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


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


*if special
   @{day |fried bread|special standard food}
   standard food
1 Like