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

Rolling Monitor

Started by lebuildman, 15 November 2014 - 08:56 PM
lebuildman #1
Posted 15 November 2014 - 09:56 PM
I was Playing in LuaLand Server, and I've builded a Big Turtle for a Store. So I wanted to make a Rolling Text:

-- Config --
monitor = "monitor_38"
text = "The Orange Turtle, the Store of GOGEL and TODTSOFTWARES items!"
slow = 2
-- Functions --
x, y = term.getSize()
function printCentered(value, height) -- For Simple GUI
  local xpos = math.floor(x/2 - string.len(value)/2)
    if height == nil then
   local cX, cY = term.getCursorPos()
   height = cY
  end
  term.setCursorPos(xpos, height) 
  term.write(value)
end
-- Simple GUI for PC --
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.clear()
printCentered("Text Panel by Buildman",math.floor(y/2))
print()
-- Program --
m = peripheral.wrap(monitor)
m.setTextScale(5)
t = text.." "
i = 0
while true do
if i == #t then i = 0 end
i = i + 1
m.write(string.sub(t, i))
sleep(slow)
end
But It don't works. Help?
MKlegoman357 #2
Posted 15 November 2014 - 10:39 PM
What do you mean it doesn't work? To me it looks like it should work, but still not as perfect as you would probably want. You might need to clear the monitor before writing the text so that the old text wouldn't be left on it.
Bomb Bloke #3
Posted 15 November 2014 - 11:04 PM
I suppose use of m.setCursorPos(1,1) (to reset the cursor position back to the start after each write) might be worthwhile.
Edited on 15 November 2014 - 10:08 PM
lebuildman #4
Posted 15 November 2014 - 11:04 PM
A Guy on the server helped me. I don't need help now
Dragon53535 #5
Posted 16 November 2014 - 12:06 AM
Hehe that guy would be me. To answer your question in a more public state, and how i did it.

local monx,mony = m.getSize() --#Get the total size for the monitor
while true do
  m.setCursorPos(1,1) --#Reset it to the far left.
  if i == #t- monx + 1 then i = 0 end --# Scroll over to the ! in your text
  i = i + 1
  m.write(string.sub(t,i,i+monx)) --#Start at i, end at i + monx, you don't need to do this exactly, you could just start at i, but i'm giving it a limit to go to :P/>
  sleep(slow)
end
Edited on 15 November 2014 - 11:08 PM