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

Monitor Scrolling?

Started by KingofGamesYami, 14 March 2014 - 03:45 AM
KingofGamesYami #1
Posted 14 March 2014 - 04:45 AM

m = peripheral.wrap("top")
m.clear()
m.setCursorPos(1, 1)
m.setTextScale(3)
m.setBackgroundColor(colors.red)
m.setTextColor(colors.black)
m.write("Hello World!")
I want to upgrade this to something that would allow me to render a large block of text on my monitor that people can scroll through.

m = peripheral.wrap("top")
redirect(m)
write("This is a large block of uninteresting example text.  Why are you still reading it?")
?button? ("/\")
?button?("\/")
?when button = clicked
?
Edited on 14 March 2014 - 03:58 AM
oeed #2
Posted 14 March 2014 - 08:25 AM
Take a look at mouse_scroll.

http://www.computerc...e_scroll_(event)

Basically, you'd have a scroll value starting at 1 and when you take 1 off it then redraw your text setting the cursor pos y value to that scroll value.


local scroll = 1
while true do
  event, dir, x, y = os.pullEvent("mouse_scroll")
  --add an if statement to prevent scroll going below 1 and above the max text length
  scroll = scroll - dir
  term.setCursorPos(1, scroll)
  print('Your text')
end
Edited on 14 March 2014 - 07:27 AM
wieselkatze #3
Posted 14 March 2014 - 02:33 PM
I think he actually ment monitors, (peripheral.wrap()), so there is no mouse_scroll event.

You could actually make 'buttons' on your monitor.
For example I'll show this on the 'printLines(x)' function. If this would print line x to line x+your monitor size, you could just put 2 buttons ('/\' and '\/') in the bottom right corner and just put a main loop in your program, e.g. this:


x = 1
while true do
  e = {os.pullEvent()}
  if e[1] == "monitor_touch" then
	if e[3] >= X-1 and e[3] <= X then -- X is your monitor width
	  if e[4] == Y-1 then -- Y is your monitor height
	  x = x + 1
	  printLines(x)
	  elseif e[4] == Y then
	  x = x - 1
	  printLines(x)
	  end
	end
  end
end

Also, as oeed said, a prevention for scrolling too far up or down.
Edited on 14 March 2014 - 01:42 PM