Concatenation (Combining Three Variables)

Hello! I’m still new to coding, and I’m following with most of the basic codes so far. But I’m having trouble with concatenation. I’ve been trying to combine three of my name variables.

Following the wiki, I’ve successfully to combines the first name and last name like this:

*set mc_firstname "Noah"
*set mc_lastname "Halloway"
*set mc_fullname (mc_firstname&" ")&mc_lastname

And it printed out just as I expected:
Code: I'm ${mc_fullname}
Printed: I'm Noah Halloway

But I wanted to add another variable (mc_middlename), but I’m not sure how to modify the code. Every time I try, I keep getting errors.

Can someone help please?

1 Like

*temp mc_fullname (((mc_firstname&" ")&mc_middlename)&" ")&mc_lastname

This should work.

At some point, though, it might be wise to consider that if you need to concatenate too many variables together (even more than 3), you might be better off just writing them all separatedly.

I'm ${mc_firstname} ${mc_middlename} ${mc_lastname}

or finding a different solution to your problem. Part of the learning process is to also reconsider your approach in that there might be a better or easier way to handle things.

Good luck with your learning!

3 Likes

Every operation needs to be wrapped in its own pair of parenthesis.

*set full_name ((((first_name & " ") & middle_name) & " ") & last_name)
                  ^^^^^^^^^^^^^^^^^^ first
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ second
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ third
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ forth

Alternatively, you can use string interpolation instead of string concatanation.

*set full_name "${first_name} ${middle_name} ${last_name}"
5 Likes

@the.normandy @cup_half_empty It worked. Thank you both, it’s working now :blush: I’ve been trying a lot of combinations, and nothing works :smiling_face_with_tear: I wish this all also in the wiki lol

3 Likes

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.