Difference between revisions of "Clear"

From ComputerCraft Wiki
Jump to: navigation, search
(shell.run("clear") shouldn't even be hinted at.)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
'''Clear''' is a built-in [[CraftOS_Shell|shell script]] for use within ComputerCraft. Running it wipes the current display and moves the cursor to the top left position.
  
== Clear ==
+
The equivalent code (for use within your own scripts) would be:
  
Clear is a program in computercraft.
+
[[term.setBackgroundColor]]([[Colors (API)#Colors|colours.black]])  -- Set the background colour to black.
You may want to use it in a script like:
+
[[term.clear]]()                           -- Paint the entire display with the current background colour.
  shell.run('clear')
+
[[term.setCursorPos]](1,1)                  -- Move the cursor to the top left position.
  print 'Your screen is emtpy new!'
+
This clears the screen so you can write a text
+
  
Clear is usefull becaus you don't have to enter a code like:
+
[[Category:Programs]]
  if turtle then
+
  a = 11
+
  else
+
  a = 17
+
  end
+
  print 'Your screen is emtpy new!'
+
  i = 0
+
  repeat
+
  print ' '
+
  i = i + 1
+
  until i == a
+
You see, a huge code!
+
New lets use a api that generate like clear:
+
  term.setCursorPos(term.getCursorPos)
+
  term.clear()
+
  term.setCursorPos(1,1)
+
a smaller code and it works for Turtle '''AND''' CraftOS
+

Latest revision as of 02:58, 25 June 2014

Clear is a built-in shell script for use within ComputerCraft. Running it wipes the current display and moves the cursor to the top left position.

The equivalent code (for use within your own scripts) would be:

term.setBackgroundColor(colours.black)  -- Set the background colour to black.
term.clear()                            -- Paint the entire display with the current background colour.
term.setCursorPos(1,1)                  -- Move the cursor to the top left position.