Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

A simple question about the print function. Why does one work and the other doesn't?

Asked by
RAYAN1565 691 Moderation Voter
8 years ago

How come this works...

print("The color is now", a.BrickColor)

and this does not?

print("The color is now  " .. a.BrickColor)

Just want to clear up my curiosity.

0
Well, I think you might get an error saying Cannot concatenate BrickColor. theCJarmy7 1293 — 8y
1
Exactly, that's the same error I'm getting. RAYAN1565 691 — 8y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

The .. operator is the string concatenation operator, meaning that it takes one string and joins it to another end to end. You are trying to concatenate a string to a BrickColor datatype, which has no direct conversion to string.

To concatenate the string and BrickColor properly, use the tostringfunction to convert the BrickColor to a string:

print("The color is now " .. tostring(a.BrickColor))
1
So basically, the ".." operator only links strings together. And in order to link the string to the BrickColor datatype using the ".." operator, you must use the tostring function to change the BrickColor datatype to a string. Correct? RAYAN1565 691 — 8y
0
Right BlackJPI 2658 — 8y
Ad

Answer this question