Difference between revisions of "Term.isColor"

From ComputerCraft Wiki
Jump to: navigation, search
(Removed chance of getting imaginary OCD by code. Fixed example not doing what it says it does.)
(whoops, no one saw this :P)
 
(3 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
{{Function
 
{{Function
 
|name=term.isColor
 
|name=term.isColor
|returns=Returns true if it's an advanced computer.
+
|returns=[[boolean_(type)|boolean]] returns true if it's an advanced computer.
 
|api=term
 
|api=term
 
|addon=ComputerCraft
 
|addon=ComputerCraft
Line 8: Line 8:
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=This program verify if the computer can display colors. <br />If it can, the computer clears the screen and changes the background to lime, otherwise, it turns computer off.
+
|desc=This program verifies if the computer can display colors.<br />Outputting information in each possible case
|code=local isAdvanced = term.isColor and term.isColor() <br />if isAdvanced then <br />    term.setBackgroundColor(colors.lime)<br />   term.clear()<br />else<br />   os.shutdown()<br />end
+
|code=
 +
-- first check if the term.isColor function exists
 +
if not term.isColor then
 +
  print("This is a pre ComputerCraft 1.45 computer, there are only normal computers! Text is always white and the background is always black")
 +
 +
-- next check if the computer is an advanced computer
 +
elseif term.isColor() then
 +
   print("This is an advanced computer, go crazy with the colours!")
 +
 +
-- all checks failed, meaning that it is a normal computer
 +
else
 +
   print("This is a normal computer. The text and background colour can be changed between black and white, but no colours!")
 +
end
 
}}
 
}}
 
}}
 
}}
  
 
[[Category:API_Functions]]
 
[[Category:API_Functions]]

Latest revision as of 18:30, 2 December 2013


Grid Redstone.png  Function term.isColor
Returns true if it's an advanced computer.
Syntax term.isColor()
Returns boolean returns true if it's an advanced computer.
Part of ComputerCraft
API term

Examples

Grid paper.png  Example
This program verifies if the computer can display colors.
Outputting information in each possible case
Code
-- first check if the term.isColor function exists
if not term.isColor then
  print("This is a pre ComputerCraft 1.45 computer, there are only normal computers! Text is always white and the background is always black")

-- next check if the computer is an advanced computer
elseif term.isColor() then
  print("This is an advanced computer, go crazy with the colours!")

-- all checks failed, meaning that it is a normal computer
else
  print("This is a normal computer. The text and background colour can be changed between black and white, but no colours!")
end