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

[Lua] [Help] Scrolling text on a monitor

Started by mike546378, 22 January 2013 - 08:51 AM
mike546378 #1
Posted 22 January 2013 - 09:51 AM
Ok, basically I am making a computer with all the names of staff for a server I am op on. I class myself as a pretty decent programmer but I can not get this program to work. What I want is the text below to scroll from the very bottom of the mon to the top then repeat. It works fine when running on the terminal but not on the 7x6 Monitor. The first couple of lines of text will be printed but it wont scroll. Any help would be much appreciated. Here is my code:


mon = peripheral.wrap("back")

screen = {
"				   Staff List",
"				   ------------",
" ",
"--------------------------------------------------------------",								  
"  Owner:",
" ",  
"	  Ph3r",
"--------------------------------------------------------------",	
"  Op:",
"	 ",
"	  mike546378",
"	  Fonrus",
"--------------------------------------------------------------",
"  Admin:",
"	 ",
"	  Aplracer1",
"	  O_lee25",
"	  Dakurlzz",
"	  Forest1989",
"--------------------------------------------------------------",
"  GMod:			  (Global Moderator)",
" ",
" ",
"--------------------------------------------------------------",
"  Mod++:",
" ",
"	  xxxxXKyleXxxxx",
"	  Mymineingz",
"--------------------------------------------------------------",
"  Mod:",
" ",	
"	  yoyo2324",
"--------------------------------------------------------------",
"  M.I.T			  (Mod In Training)",	  
" ",
"	  Muffinxl",
"--------------------------------------------------------------",
"  Donator:",
" ",
"	  mike546378  ",
"--------------------------------------------------------------",
}
x, y = mon.getSize()
scroll = -25


local function draw()
for z = scroll - y, scroll + y do
  print(screen[z])
  end
end

draw()

for i = 1,60 do
	scroll = scroll + 1
	sleep(0.5)
	print(screen[z])
	draw()
end

shell.run("monitor", "back", "mon2")

If it makes a difference I am using computercraft version 1.4.1 in the latest build of tekkit classic.
Thx again for any help.
It also does not give me an error, it just keeps running until I terminate it or restart the computer.

If any more info is needed just ask
ikke009 #2
Posted 22 January 2013 - 10:57 AM
x, y = mon.getSize()
scroll = 1


local function draw()
for z = scroll, scroll + y do
  print(screen[z])
  end
end

draw()

for i = 1,#screen-y do
        scroll = scroll + 1
        sleep(0.5)
        draw()
end
I'm not sure but maybe this works.. what is does in the draw function is it prints the lines from the amount it scrolled down till the amount it scrolled down + the length of the screen
if its done that it scrolls down one more and repeats untill the last line from the screen table reaches the bottom of the monitor (#screen-y)
now to scroll back up it should be fairly easy to reverse it.
theoriginalbit #3
Posted 22 January 2013 - 11:02 AM
Try clearing the screen each time a new one is drawn and tell us the result… are those top lines still there? or is it now empty?

Side note:
I suggest instead of re-running the program with shell.run having an infinite loop
while true do
otherwise the stack will fill up and your program will error…
mike546378 #4
Posted 22 January 2013 - 12:04 PM
Thank you soo much guys.
Here is the code that I changed and it now works perfectly.


while true do
    mon.clear()
    scroll = -34
   for i = 1,72 do
        scroll = scroll + 1 
        sleep(0.5)
        mon.clear()
        draw()
    end
end

Although I didn't use your method ikke009 thank you for still trying to help. This seems like a good community and I will be coming back if I have any more questions. I did find a bug where it would stick after printing mod and not get cleared but removing the top row of monitors solved this (could be down to people using World edit around it but idk). Also that is a really good tip about the while true do loops. I always wondered why the programs would crash after a while so I would usually just add os.reboot() at the end. Never even taught it could be the shell.run that was causing it.