Difference between revisions of "Clear"

From ComputerCraft Wiki
Jump to: navigation, search
(Add code tags, remove term.clear (has a seperate page Term.clear), and fix grammar errors and stuff)
Line 2: Line 2:
 
== Clear ==
 
== Clear ==
  
Clear is a program in computercraft.
+
Clear is a built-in program in ComputerCraft.
 
You may want to use it in a script like:
 
You may want to use it in a script like:
 +
<pre>
 
   shell.run('clear')
 
   shell.run('clear')
   print 'Your screen is emtpy new!'
+
   print('Your screen has been cleared!')
This clears the screen so you can write a text
+
</pre>
 
+
or just type:
Clear is usefull becaus you don't have to enter a code like:
+
<pre>
  if turtle then
+
clear
  a = 11
+
</pre>
  else
+
in the computer.
  a = 17
+
This clears the screen so you can write text.
  end
+
'''NOTE: It is not recommended to use the above code in a program, instead use [[Term.clear]]. It is only recommended to use this program to clear the screen through the shell.'''
  print 'Your screen is emtpy new!'
+
== term.clear ==
  i = 0
+
For term.clear, visit [[Term.clear]]
  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.getSize)
+
  term.clear()
+
  term.setCursorPos(1,1)
+
a smaller code and it works for Turtle '''AND''' CraftOS
+
 
+
== term.clear() ==
+
 
+
New lets look to the api.
+
How does it work?
+
Can it clear the whole screen if the cursor is in the midle?
+
 
+
No it cant!
+
 
+
If you place it in the midle, anything behind the cursor would not be deleted!
+
 
+
Thats where getSize comes in.
+
It checks how grand the screen is(default 50,18).
+
 
+
So it always clears the exact screen and not less or more!
+

Revision as of 19:11, 2 September 2012

Clear

Clear is a built-in program in ComputerCraft. You may want to use it in a script like:

  shell.run('clear')
  print('Your screen has been cleared!')

or just type:

clear

in the computer. This clears the screen so you can write text. NOTE: It is not recommended to use the above code in a program, instead use Term.clear. It is only recommended to use this program to clear the screen through the shell.

term.clear

For term.clear, visit Term.clear