147 posts
Location
My Computer
Posted 03 December 2013 - 04:29 PM
What I want to do is make the computer ask you for a color:
local color = read()
Then set the background color to that variable.
What I am using:
term.setBackgroundColor(color)
But it says expected number.
Any help?
1688 posts
Location
'MURICA
Posted 03 December 2013 - 04:49 PM
It doesn't quite work like that. read() returns a string, and if you typed "colors.red", you would get "term.setBackgroundColor("colors.red")", and not "term.setBackgroundColor(colors.red)"
What you should do is take the input string, then access the colors table using the string.
local color = read()
term.setBackgroundColor(colors[color])
Note that you would be typing "red" instead of "colors.red" for this method. If you typed in "red":
local color = "red"
term.setBackgroundColor(colors["red"]) --# colors["red"] is the same as colors.red, as colors["blue"] is the same as colors.blue