This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
samdeman22's profile picture

I need a bit of help drawing this box

Started by samdeman22, 07 August 2012 - 01:29 PM
samdeman22 #1
Posted 07 August 2012 - 03:29 PM
So, I wont be at my minecraft computer for a while so I want to know if this'll work before I come back.

I want to draw a box right around the screen from the second line downwards.
sorry this is quite a big peice of code so it must be messy



-- Section: 1
-- Variables
length = (length of screen) -- I will insert the length and height of the screen later
height = (height of screen)

-- Secion: 2
-- Functions

-- draw the top and bottom
-- topChar/bottomChar - enter the characters for use.
-- cornerBool - checks if you want special corner characters
-- cornerChar - the caracter for corner

function drawTopandBottom( boxChar, cornerBool, cornerChar )
   local function Aline()   -- Aline() writes the line WITH corners
	  local x = 2
	  for
		 i = 0, (length -2), 1 do
		 term.setCursorPos( x, y )
		 print( boxChar )
		 local x = x + 1
		 sleep(0.05)
	  end
   end

   local function Bline()   -- Bline() writes the line WITHOUT corners
	  local x = 1
	  for
		 i = 0, (length), 1 do
		term.setCursorPos( x, y )
		sleep( 0.05 )
	  end
   end
  
   if cornerBool == true
   then
	  term.clear()
	  local y = 2
	  term.setCursorPos( 1, y )
	  print( cornerChar )
	  Aline()
	  print( cornerChar )
	  local y = height
	  term.setCursorPos( 1, y )
	  print( cornerChar )
	  term.setCursorPos( 2, y )
	  Aline()
	  term.setCursorPos( x, y )
	  print( cornerChar )
   elseif cornerBool == false
   then
	  term.clear()
	  term.setCursorPos( 1, 2 )
	  local y = 2
	  Bline()
	  local y = height
	  term.setCursorPos( 1, y )
	  Bline()
   end
end

function drawSides( sideChar )
   term.setCursorPos( 1, 3 )
   for i = 0, (height - 4), 1 do
	  print( sideChar )
   end
   term.setCursorPos( length.. - 1, 3 )
   for i = 0, (height - 4 ), 1 do
	  local x,y = term.getCursorPos
y = y + 1
term.setCursorPos( y )
   end
end



I will then use the functions like…


drawTopAndBottom( "-", true, "x" )
drawSides( "|" )

Things I'm not sure about:
- my loops
- the whole of the drawSides() function
wilcomega #2
Posted 07 August 2012 - 03:34 PM
what is exactly wrong. are you getting a error is it prnting wrong things is it printing at wrong position or is your code just messy and you want others to make a total rewrite? :P/>/>
samdeman22 #3
Posted 07 August 2012 - 04:04 PM
I wont have access to a computer to play minecraft on for a while, I just want to know if this will work. I guess you could copy it (including the part where it runs the functions) into a text file, then put it in your computercraft file and run "yourfile.txt"
wilcomega #4
Posted 07 August 2012 - 04:07 PM
or you download the computercraft emulator to see if it works
samdeman22 #5
Posted 07 August 2012 - 04:15 PM
ok i could try that, does anything look wrong with it then?
Cranium #6
Posted 07 August 2012 - 05:32 PM
I had the same problem with my borders. I got help, and was rewarded with this awesome piece of code:

function border()
	local w, h = term.getSize()
	local s = "+"..string.rep("-", w - 2).."+"
	term.setCursorPos(1, 1)
	term.write(s)
	for y = 2, h - 1 do
			term.setCursorPos(1, y)
			term.write("|")
			term.setCursorPos(w, y)
			term.write("|")
	end
	term.setCursorPos(1, h)
	term.write(s)
end
This draws a border that looks like this:

+----------+
|	   |
|	   |
+----------+
It also makes it as big as the screen is, no matter what!