Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------
- -- Config --
- ------------
- --Time in seconds between scroll updates
- local updateSpeed = 0.1
- --Text to scroll
- local text = "This is a test!"
- --Whether or not to scroll left-to-right
- local scrollLeftToRight = false
- ---------------------------------
- -- Dont edit past here, thanks --
- ---------------------------------
- --Initial Variable Setup
- local m = peripheral.find("monitor")
- local mX,mY = m.getSize()
- local cX = 0
- if (scrollLeftToRight == true) then
- cX = -string.len(text)
- end
- --Function to run if scrollLeftToRight == false
- function rtl()
- cX = cX+1; --Add one to the current X position of the text
- m.clear() --Clear the monitor
- m.setCursorPos(mX-cX,mY/2) --Set the cursor position of the monitor to the calculated coordinates
- m.write(text) --Write our text
- if (mX-cX < 0) then --If we are starting to lose text to the side of the screen...
- m.setCursorPos(mX-(cX-mX),mY/2) --Set the cursor pos to the end of the monitor, relative to where the main text is
- m.write(text) --Write the same text - this gives the illusion of it wrapping around.
- end
- if (cX-mX >= string.len(text)) then --If the text is all the way off the screen, reset the current position.
- cX = cX-mX
- end
- end
- --Function to run if scrollLeftToRight == true
- --(Nearly identical to rtl(), comments show differences)
- function ltr()
- cX = cX+1
- m.clear()
- m.setCursorPos(cX,mY/2) --Start from front of monitor instead of end
- m.write(text)
- if (cX > mX-string.len(text)) then
- m.setCursorPos(cX-mX,mY/2) --Start from front of monitor instead of end
- m.write(text)
- end
- if (cX-mX >= 0) then
- cX = cX-mX
- end
- end
- --Loop function. Simply chooses which direction to scroll in, based on config.
- -- Technically this COULD be in the while loop instead of its own function, but meh.
- function main()
- if scrollLeftToRight then
- ltr()
- else
- rtl()
- end
- end
- --Main loop. Not that interesting.
- while true do
- main()
- sleep(updateSpeed)
- end
Advertisement
Add Comment
Please, Sign In to add comment