# Multireplace documentation?

**URL:** <https://forum.choiceofgames.com/t/multireplace-documentation/41144>\
**Category:** ChoiceScript Help\
**Created:** [July 18, 2018, 1:19pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144 "2018-07-18T13:19:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CypherK](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@CypherK](https://forum.choiceofgames.com/u/CypherK)\
**Post date:** [July 18, 2018, 1:19pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/1 "2018-07-18T13:19:28Z")

</div>

Is the multireplace documented, somewhere?  
I didn’t encounter it in my pass through the [“full” tutorial](https://forum.choiceofgames.com/t/choicescript-full-tutorial-finished/16130), nor on the wiki pages, so when I first encountered it in the forums, I took it for a ternary operator

```
@{<booleanValue> <stringValueIf> | <stringValueElse>}

```

But then I came across another post that made me believe the code above was a special case of something akin to

```
@{<intValue> <stringValue1> | <stringValue2>|... | <stringValueN> }

```

I was half expecting

```
*temp foo 2
*temp bar @{foo 0 | 1 | 2 }
*set bar +2
${bar}

```

to work, but that gives me an

```
Invalid expression, couldn't extract another token: @{foo 0 | 1 | 2 }

```

Still, I’d like to know for sure.  
Is there some kind of documentation on the multireplace?  
(Or better yet, a choice script grammar file?😛 )

---

<div class="post-metadata">

**Author:** ![RETowers](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/retowers/32/21477_2.png) [@RETowers](https://forum.choiceofgames.com/u/RETowers)\
**Post date:** [July 18, 2018, 1:29pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/2 "2018-07-18T13:29:02Z")

</div>

No, I plan to redo all ChoiceScript documentation as soon as I have some time. As for your integer example, multireplace is arrayed from 1, not 0.

---

<div class="post-metadata">

**Author:** ![CypherK](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@CypherK](https://forum.choiceofgames.com/u/CypherK)\
**Post date:** [July 18, 2018, 2:09pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/3 "2018-07-18T14:09:14Z")

</div>

Wait, are you suggesting the integer example should work?

`foo` is set to 2 in the example, so if

```
*temp bar @{foo 0 | 1 | 2 }

```

would pass, I’d expect `bar` to be equal to 1.  
Except the assignment fails.  
At first, I was assuming that the error meant multireplace was returning a string, rather than a number, which means `1` - in the absence of question marks - is taken as an invalid variable name to look up.

But then neither

```
*temp foo 2
*temp a "A"
*temp b "B"
*temp c "C"
*temp bar @{(foo)a|b|c}

```

Nor

```
*temp bar ${@{(foo)a|b|c}}

```

were working and I just settled in “it’s not possible, you have to declare the variable separately”, e.g:

```
*temp foo 2
*temp bar 0-1
*set bar @{foo 0|1|2}

```

But that doesn’t work either (nor does it work when declaring `bar` a string variable).  
(Again “invalid expression, couldn’t extract another token”.)

Soo … I eventually settled for “can only be used to display text”.

Am I wrong about that and making a different mistake?

---

<div class="post-metadata">

**Author:** ![RETowers](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/retowers/32/21477_2.png) [@RETowers](https://forum.choiceofgames.com/u/RETowers)\
**Post date:** [July 18, 2018, 2:33pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/4 "2018-07-18T14:33:14Z")

</div>

Ah, I didn’t catch the problem the first time around because there’s actually _two_ problems with your syntax, I noticed the first one, and I corrected it without thinking about it deeply enough. My mistake.

First: What I mentioned before, it’s arrayed from 1, not 0, so you should be using `@{foo 1 | 2 | 3 }` not `@{foo 0 | 1 | 2 }` (Assuming I’m understanding your intentions correctly.) (Although this shouldn’t have caused a crash, as this means you’re actually calling the place marked `1`, rather than a space beyond the `2`, which should have been obvious, but apparently I’m a little tired and didn’t think it through.)

Second, and this is what’s actually causing your error, it’s for inline use. To use it in a `*command` like `*temp` or `*set`, you need to wrap it in quotation marks. So something like this:

```
*temp foo
*temp bar "@{foo 1 | 2 | 3 }"
*comment Note the quotation marks around the replace.
*set bar +2
This should be 4: ${bar}

Alteratively
*temp bar "@{foo 0|1|2}"
*set bar +2
With your series, we'll get the second number from multireplace (1) + 2 = ${bar}.

```

Or, a simpler example:

```
*temp foo 1
*rand foo 1 3
The random number is @{foo one|two|three}.

```

---

<div class="post-metadata">

**Author:** ![Mary\_Duffy](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/mary_duffy/32/5311_2.png) [@Mary\_Duffy](https://forum.choiceofgames.com/u/Mary_Duffy)\
**Post date:** [July 18, 2018, 3:19pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/5 "2018-07-18T15:19:33Z")

</div>

@CypherK isn’t the first person to fall afoul of this, and many of my authors have assumed it’s arrayed from 0, not 1. So, FWIW it’s something rather fiddly, and something to think about when including it in your documentation.

Someone should add this to the wikia, too…

---

<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, 3:55pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/6 "2018-07-18T15:55:33Z")

</div>

> [@Mary\_Duffy](#):
>
> Someone should add this to the wikia, too…

Yeah! Who’s handling the wiki? It’s like outdated for years!

---

<div class="post-metadata">

**Author:** ![Mary\_Duffy](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/mary_duffy/32/5311_2.png) [@Mary\_Duffy](https://forum.choiceofgames.com/u/Mary_Duffy)\
**Post date:** [July 18, 2018, 4:54pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/7 "2018-07-18T16:54:32Z")

</div>

The wikia is a community project, just like Wikipedia, so the responsibility is on anyone and no one’s shoulders to edit it. It is also an amazing project, and I’m very happy it exists.

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [July 18, 2018, 7:49pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/8 "2018-07-18T19:49:13Z")

</div>

Indeed. If anyone sees something that’s obviously out-of-date on the wiki, please do consider taking the time to update it! If there are any pages you don’t have permission to edit, I think myself and @Vendetta can both grant permission.

---

<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, 9:33pm UTC](https://forum.choiceofgames.com/t/multireplace-documentation/41144/9 "2018-07-18T21:33:55Z")

</div>

I mean… it’s been years since my last attempt at editing wikis on those games’ wiki site. I shudder at the sight of these html/wiki-syntax codes, again.

 ![e](https://global.discourse-cdn.com/choiceofgames/original/3X/7/a/7a44d62cdbaa1a43884224143682811c98863a9f.PNG)
