Help with concatenation?

I’m trying to set up naming in my game, but the guide on the wiki :

Isn’t helping. I keep getting an Operator error “expecting OPERATOR, was OPEN_PARENTHESIS[(]”

I don’t want it as “first name” “last name”, but “first name” “val” “last name”. Can anyone help me figure out how to set it up?

If you’re just trying to print that, then assuming firstname and lastname are already created and assigned the right values,

${firstname} val ${lastname}

will work.

*create firstname “Unknown”
*create lastname “Unknown”
*create fullname “Unknown val Unknown”
*set fullname ({firstname} val {lastname})

Gets me

startup line 27: Invalid expression, couldn’t extract another token: {firstname} val {lastname})

Try this:

*set fullname  (firstname&" val ")&lastname

this should help.


@P_Tigras the point of concatenating in so that you don’t have to keep writing that 3-variable name over and over, it’s much easier to just write one variable.

You might need to copy the example in the Concatenation section a little more closely if you want it to be helpful…

*create firstname "Unknown"
*create lastname "Unknown"
*create fullname "Really Awfully Unknown"

*set fullname (firstname&" val ")&lastname
My name is ${fullname}.

Try running it in CSIDE to confirm that it works.

Edit: NinjaLamia!

1 Like

That worked, thank you all for your help.

I understand the point of concatenation. :wink: I simply failed to make the very tiny leap of logic from the name of the link that concatenation was what he desired since he didn’t specify it in his post outside of the link itself. It’s 3am here and I’m tired…

1 Like

I just don’t think I’m understanding concatenation.

*set appearance ((hair&","&eyes)&(skin))

*set appearance ((hair&",")&eyes",")&skin

and other variants all come back with an operator error

you have to be careful of where you use the brackets, and where not to use them.

using concatenation, groups them into groups of two. you can only concatenate 2 parts at a time

hair&", " 
being the first group, bracket them. This makes them one part. after this,
(hair&", ")&eyes
now this means that there are still 2 "parts" there, because the brackets cause hair and the comma to form into 1 part.
(hair&", ")&(eyes&", ")
now, hair and first comma are part 1, with eyes and second comma being part 2
((hair&", ")&(eyes&", "))&skin
this should make everything in the brackets part 1, while skin is now part 2.

Haven’t tested it, but this should work now.

4 Likes

That worked, thank you so much. I don’t think I’d ever have figured out how it grouped them on my own.

1 Like

Totally unrelated but I read Help with nanning instead of Help with naming and laughed so much anyway I’ll see myself out.

Terrific explanation. Worth noting that the “only 2 things at a time” rule applies to many things in ChoiceScript:

2 Likes