Concatenation of stats and variables

Hello, I’m having trouble with stats screen. Not sure how to explain but I want players to choose three apparance variables (skin color, eyes and hair etc.) and I want to show this variables under appearance title on the stats screen.

My code looks like this:

*set appearance (skin2&", ")&eyes2

This works but whenever I try to add &hair2

*set appearance (skin2&", ")&eyes2&hair2

it doesn’t work.

I assume you’ve taken a look at this, but I’ll put it here for a resource.

Yes, but unfortunately I’ve the analytic brain of a baboon and couldn’t understand a thing…

Well, I know two ways for doing this. The first is the one you’re currently trying: grouping them in parentheses. It’s like this

*set firstname "John"
*set lastname "Smith"
*set title "Mr."
then
*set fullname (((title&" ")&firstname)&" ")&lastname)

That’s the complicated way, because it’s a bit hard to get the parentheses right.

The other way I know is the “long” way, that consist of setting the string using a chain of *set commands

*set fullname title
*set fullname &" "
*set fullname &firstname
*set fullname &" "
*set fullname &lastname

Hope it helps

1 Like

It did help! Thank you very much

It’s my pleasure

ChoiceScript parser is limited. Each operation must be its own expression, which means that they must be surrounded by paranthesis. That’s why @Ferddai’s way worked.

Another way of achieving the same result is by using string interpolation. If you’re concatenating many strings, it might be easier to read.

*set fullname "${title} ${firstname} ${lastname}" 

The ${} syntax will replace the internal expression by its value at runtime.

1 Like