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

Finding a Specific Character

Started by ryan0788, 10 March 2012 - 03:31 AM
ryan0788 #1
Posted 10 March 2012 - 04:31 AM
Hi, I'm trying to make a GUI for a 'sort of' operating system I'm working on but I need to be able to find what character is in a a specific place in the console. Say I have the coordinates 5, 4 and I need to find what letter/number/symbol is at that point.


function drawFullBorder()
for y = 0, sizeY do
  for x = 0, sizeX do
   term.setCursorPos(x, y)
   if (x == 1 and y == 1) or (x == 1 and y == sizeY) or (x == sizeX - 1 and y == 1) or (x == sizeX - 1 and y == sizeY) then
	write("*")
   elseif x == 1 or x == sizeX - 1 then
	write("|")
   elseif (y == 1 or y == sizeY) and x < sizeX then
	write("-")
   else
	write([b]**Here's where I need to find what it's going to replace if I draw here.**[/b])
   end
  end
end
term.setCursorPos(1, sizeY)
end
Casper7526 #2
Posted 10 March 2012 - 05:01 AM
Then you need to store the screen data in a table and print from that table.

line[1] = "Hello World"
line[2] = "Hey there"

for x = 1, #line do
print (line[x])
end

print (string.sub(line[1], 1, 1))   -- print the first char of line 1
print (string.sub(line[2], 5, 5))   -- print the 5th char of line 2
ryan0788 #3
Posted 10 March 2012 - 03:36 PM
But the problem is that I print with different functions at different times and i just want this function to replace the characters that it needs to, while maintaining what was there before. Is there any way I can retrieve what character is at a certain point?

   else
	    write(term.getCharAt(x, y))
   end
Sebra #4
Posted 10 March 2012 - 03:39 PM
seems no. Store all, you write.
ryan0788 #5
Posted 10 March 2012 - 03:55 PM
Found a way around it - Just don't draw there and it'll keep what was there before. Thanks :mellow:/>/>