Multireplace documentation?

Is the multireplace documented, somewhere?
I didn’t encounter it in my pass through the “full” tutorial, 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?:stuck_out_tongue: )

1 Like

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.

2 Likes

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?

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}.
3 Likes

@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…

1 Like

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

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.

5 Likes

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.

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.