Detecting advanced computers
#1
Posted 05 December 2012 - 03:58 AM
#2
Posted 05 December 2012 - 04:22 AM
#4
Posted 05 December 2012 - 04:51 AM
if term.isColor() then
term.setTextColor(colors.lime)
print("Hello!")
term.setTextColor(colors.white)
else
print("Hello!")
end
If you were talking about code to just ignore the color commands, I have been wondering about the same thing
if not term.isColor() then
string.ignore("term.setTextColor()")
string.ignore("term.setBackgroundColor()")
end
#5
Posted 05 December 2012 - 04:53 AM
ChaddJackson12, on 05 December 2012 - 04:51 AM, said:
if not term.isColor() then
string.ignore("term.setTextColor()")
string.ignore("term.setBackgroundColor()")
end
I wish it were that easy....
#6
Posted 05 December 2012 - 04:55 AM
EDIT: I got it! make a program that will run through your file and put -- infront of any unsupported command.
#7
Posted 05 December 2012 - 04:57 AM
local function doColor(fg,bg) end if term.isColor() then doColor=function(fg,bg) if fg then term.setForegroundColor(fg) end if bg then term.setBackgroundColor(bg) end end end
Then I just called doColor to set the color instead of calling the term functions directly.
:edit: :facepalm: How am I just NOW discovering that basic computers can do black text on white backgrounds? Never seen it done and never thought to test it myself until just now. So battleship needs more work after all, can greatly improve the rendering of the basic computer version with this knowledge!
#8
Posted 05 December 2012 - 04:58 AM
ChaddJackson12, on 05 December 2012 - 04:51 AM, said:
if not term.isColor() then
string.ignore("term.setTextColor()")
string.ignore("term.setBackgroundColor()")
end
No, not even a little bit.
Also, if you just want color to show up on advanced machines for what you're printing, a simple ternary operation will do nicely.
term.setTextColor(term.isColor() and colors.white or colors.black)
term.setBackgroundColor(term.isColor() and colors.blue or colors.white)
term.write("Some Highlighted Text")
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
#9
Posted 05 December 2012 - 05:40 AM
Lyqyd, on 05 December 2012 - 04:58 AM, said:
Also, if you just want color to show up on advanced machines for what you're printing, a simple ternary operation will do nicely.
term.setTextColor(term.isColor() and colors.white or colors.black)
term.setBackgroundColor(term.isColor() and colors.blue or colors.white)
term.write("Some Highlighted Text")
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
To explain how this works in a non color computer you can use term.setTextColor() and term.setBackgroundColor() you can only use black or white . If you give those functions any other input it will fail and give an error. The code from Lyqyd works because if it is color it returns the color if not it returns the other color the function then sets the color.
another way to do it is
local backColor = colors.red
local textColor = colors.blue
if term.isColor() then
backColor = colors.white
textColor = colors.black
end
term.setBackgroundColor(backColor)
term.setTextColor(textColor)
print("hello")
#10
Posted 05 December 2012 - 05:53 AM
Quick question though, from what I got from this is that colors.black and colors.white can be used on non-colored computers? Or should I just use the term.setBackgroundColor(term.isColor() and colors.red) only?
(only reason i ask these questions is because i can't test at work :/)
#11
Posted 05 December 2012 - 06:34 AM
#12
Posted 05 December 2012 - 07:24 AM
ChaddJackson12, on 05 December 2012 - 04:51 AM, said:
Actually, it is that easy. I do this for almost all of my adv. programs - overwriting the term functions.
local setTextColor = term.setTextColor
local setBackgroundColor = term.setBackgroundColor
function term.setTextColor(...)
if term.isColor() then
setTextColor(...)
end
end
function term.setBackgroundColor(...)
if term.isColor() then
setTextColor(...)
end
end
#13
Posted 05 December 2012 - 08:45 AM
Kingdaro, on 05 December 2012 - 07:24 AM, said:
ChaddJackson12, on 05 December 2012 - 04:51 AM, said:
Actually, it is that easy. I do this for almost all of my adv. programs - overwriting the term functions.
local setTextColor = term.setTextColor
local setBackgroundColor = term.setBackgroundColor
function term.setTextColor(...)
if term.isColor() then
setTextColor(...)
end
end
function term.setBackgroundColor(...)
if term.isColor() then
setTextColor(...)
end
end
Unfortunately, this would remove entirely the ability to set the color on non-advanced computers, rather than just limiting them to the colors they can use.
#14
Posted 05 December 2012 - 10:06 AM
But at that point, with my method, you may as well just make your own local functions to do it.
local allowed = {[1]=true, [32768]=true}
function setFG(color)
if not term.isColor() and not allowed[color] then
return
end
term.setTextColor(color)
end
function setBG(color)
if not term.isColor() and not allowed[color] then
return
end
term.setBackgroundColor(color)
end
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











