Difference between revisions of "Clear"

From ComputerCraft Wiki
Jump to: navigation, search
Line 30: Line 30:
  
 
New lets look to the api.
 
New lets look to the api.
 
 
How does it work?
 
How does it work?
 
 
Can it clear the whole screen if the cursor is in the midle?
 
Can it clear the whole screen if the cursor is in the midle?
  
Line 40: Line 38:
  
 
Thats where getSize comes in.
 
Thats where getSize comes in.
 
+
It checks how grand the screen is(default 50,18).
It checks how grand the screen is(default 50,18)
+
  
 
So it always clears the exact screen and not less or more!
 
So it always clears the exact screen and not less or more!

Revision as of 16:51, 2 September 2012

Clear

Clear is a program in computercraft. You may want to use it in a script like:

 shell.run('clear')
 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:

 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.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!