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

How to do colors

Started by Entropy, 26 March 2013 - 11:02 PM
Entropy #1
Posted 27 March 2013 - 12:02 AM
Hi, I've been wondering how I change the text and background color. I'm pretty sure i've seen it done. Like I want a white background and black text. I've made the functions for them but I don't know the code that goes inside :/. So if someone could send me in the right direction. I also wouldn't mind some help on GUI's. Thanks.
Engineer #2
Posted 27 March 2013 - 12:32 AM
For on an advanced monitor/computer you can choose all colors*, but for a non-advanced computer you can only set it to black or white.
To set your text colors you do:

term.setTextColor( color )
And for your background:

term.setBackgroundColor( color )
You can set the color by doing:

term.setTextColor( colors.red )
-- OR
term.setTextColor( 16384 )

You can find those color values on the link below,

I hope I helped you :)/>

* All colors
Ristyo #3
Posted 27 March 2013 - 12:53 AM
If you want to set the WHOLE background color use this :
term.setBackgroundColor(colors.YourPreferredColor)
term.clear()
Entropy #4
Posted 27 March 2013 - 09:19 PM
Yes thank you both of you. I also saw a thread on what Ristyo said. So I tried it in Lua terminal thing and when I did it, it would remove the color as I typed… Any ideas? Screenie: http://puu.sh/2oOk0 in the lua terminal I would type it. It would be fine I write on toip of the color but once i pressed enter (to like go to the next line and whatever) it would start removing color. I also tried it in a computer. Same problem
Engineer #5
Posted 27 March 2013 - 09:25 PM
term.setBackgroundColor( color )
term.setTextColor( colors.red ) – I like red
term.clear()

Should do the job. Maybe it is the lua interpreter, try it out in a test program.
theoriginalbit #6
Posted 27 March 2013 - 09:26 PM
make sure that when attempting to change colours to do this

if term.isColor and term.isColor() then
  -- this is a computer from cc1.4+ and is an advanced computer and you can change to any colour you wish.
elseif term.isColor then
  -- this is a computer from cc1.4+ and is a non-advanced computer or TURTLE and you can change between black and white
else
  -- this is a computer before cc1.4 and it means that colours are not supported
end
Entropy #7
Posted 27 March 2013 - 09:47 PM
make sure that when attempting to change colours to do this

if term.isColor and term.isColor() then
  -- this is a computer from cc1.4+ and is an advanced computer and you can change to any colour you wish.
elseif term.isColor then
  -- this is a computer from cc1.4+ and is a non-advanced computer or TURTLE and you can change between black and white
else
  -- this is a computer before cc1.4 and it means that colours are not supported
end
Why do you put "If term.isColor and term.isColor()? Because this doesnt really answer my question. Or I just don't understand it xD.
Doyle3694 #8
Posted 27 March 2013 - 09:51 PM
He first check if term.isColor exists, if not then you are using an old version of cc that does not support colors. after that he runs term.isColor() to check if the computer is advanced. If he weren't to put that first term.isColor the second would raise an attempt to call nil exception if it was old version of cc
theoriginalbit #9
Posted 27 March 2013 - 09:57 PM
Because this doesnt really answer my question. Or I just don't understand it xD.
It wasn't me answering your question, it was me telling you a very important piece of information to make a really good cc program that is compatible across many versions.

as fo your question, the reason the colour is removed is because it is the shell. the shell sets the background colour to black. so each time you type a letter it changes the background colour behind each letter.
Entropy #10
Posted 27 March 2013 - 09:59 PM
Because this doesnt really answer my question. Or I just don't understand it xD.
It wasn't me answering your question, it was me telling you a very important piece of information to make a really good cc program that is compatible across many versions.

as fo your question, the reason the colour is removed is because it is the shell. the shell sets the background colour to black. so each time you type a letter it changes the background colour behind each letter.
Anyway to fix that? Btw thank you guys for the help :)/>
theoriginalbit #11
Posted 27 March 2013 - 10:01 PM
Anyway to fix that? Btw thank you guys for the help :)/>
Write a new shell program. why do you want the background white behind the shell?
Entropy #12
Posted 27 March 2013 - 10:05 PM
Anyway to fix that? Btw thank you guys for the help :)/>
Write a new shell program. why do you want the background white behind the shell?
It something for ShadowKat. Im sorta lost with it :/ Pm if your willing to sorta help me a bit. :)/>
Doyle3694 #13
Posted 27 March 2013 - 10:08 PM
term.clear() works too