This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cheesety210's profile picture

Can I print several things on the same line?

Started by Cheesety210, 29 March 2013 - 06:15 PM
Cheesety210 #1
Posted 29 March 2013 - 07:15 PM
This is my first self-written program.

print("What is your name?")
local name = read()
print("What is your favorite color?"
local color = read()
print("Your name is")
print(Name)
print("Your favorite color is"
print(color)

It looks like:
Your name is
Jeff
Your favorite color is
Blue

How do I get it like:
Your name is Jeff. Your favorite color is Blue.
(All in one line)
faubiguy #2
Posted 29 March 2013 - 07:27 PM
You can use the .. operator to concatenate the strings into a single one, which can be printed all at once. Example
print("Your name is  " .. name .. ". Your favorite color is " .. color .. ".")

If you're using print, you can also pass the strings as separate arguments.
Cheesety210 #3
Posted 29 March 2013 - 07:33 PM
It works, thanks!