This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Monitor Scrolling?
Started by Grey_M62, 14 July 2012 - 11:20 PMPosted 15 July 2012 - 01:20 AM
I have been playing on a computercraft server, and i saw that someone had set up a 1x4 monitor, and made it print announcements that scrolled along the screen. I want to know how to do this. I want the text to be as tall as the screen, and to scroll.
Posted 15 July 2012 - 01:50 AM
I found out how to scroll, but i have a new problem. here is my code:
mon = peripheral.wrap("back")
mon.setTextScale(4)
text = "Grey_M62 is awesome."
pos = 20
while true do
mon.clear()
mon.setCursorPos(pos, 1)
mon.write(text)
sleep(0.2)
if pos == -21 then
pos = 20
else
pos = pos - 1
end
end
My problem is that it takes too long to repeat the message. can someone help?Posted 15 July 2012 - 01:51 AM
I would give you code but im in a hurry so what you do is look on the monitor page on the wiki and use that method to set the size and print out the characters in a while loop with delays, like this: while true do write("a") sleep(1) write("b") sleep(1)….end Hope i helped :P/>/>
BTW, i know what server your talking about, everybody join ccnet.ddns.com:25564
U posted right when i did
BTW, i know what server your talking about, everybody join ccnet.ddns.com:25564
U posted right when i did
Posted 15 July 2012 - 01:52 AM
So you shorten the delay to 0.1 or lower?I know ur reading this, mystic.
Posted 15 July 2012 - 01:57 AM
that makes the text go by faster, but doesn't decrease the delay between the text.So you shorten the delay to 0.1 or lower?I know ur reading this, mystic.
Posted 15 July 2012 - 01:57 AM
Here's some code I use:
I was writing this post.
-- The text to show on the monitor
local tText = {
"First Line",
"Second Line",
"All the lines you want",
"If they fit on the monitor"
}
-- The side the monitor is on
local sSide = "back"
-- The text scale
local nTextScale = 3
local function printScroll(mon, t)
local w, h = mon.getSize()
local scroll = 1
local maxLen
for i, line in ipairs(t) do
if not maxLen or #line > maxLen then
maxLen = #line
end
end
while true do
mon.clear()
for i, line in ipairs(t) do
mon.setCursorPos(w - scroll, i)
mon.write(line)
end
scroll = scroll + 1
if scroll >= w + maxLen then
scroll = 1
end
sleep(0.15)
end
end
term.clear()
term.setCursorPos(1, 1)
print("Scrolling text on the monitor...")
local mon = peripheral.wrap(sSide)
mon.setTextScale(nTextScale)
printScroll(mon, tText, sx)
:P/>/>So you shorten the delay to 0.1 or lower?I know ur reading this, mystic.
I was writing this post.
Posted 15 July 2012 - 02:03 AM
all that does is print "First Line" with the same delay in between. i know there is a better way, because on the server, there is one that repeats, and doesn't clear the text every time.Here's some code I use:-- The text to show on the monitor local tText = { "First Line", "Second Line", "All the lines you want", "If they fit on the monitor" } -- The side the monitor is on local sSide = "back" -- The text scale local nTextScale = 3 local function printScroll(mon, t) local w, h = mon.getSize() local scroll = 1 local maxLen for i, line in ipairs(t) do if not maxLen or #line > maxLen then maxLen = #line end end while true do mon.clear() for i, line in ipairs(t) do mon.setCursorPos(w - scroll, i) mon.write(line) end scroll = scroll + 1 if scroll >= w + maxLen then scroll = 1 end sleep(0.15) end end term.clear() term.setCursorPos(1, 1) print("Scrolling text on the monitor...") local mon = peripheral.wrap(sSide) mon.setTextScale(nTextScale) printScroll(mon, tText, sx)
:P/>/>So you shorten the delay to 0.1 or lower?I know ur reading this, mystic.
I was writing this post.
Posted 15 July 2012 - 03:05 AM
Each line is a different line in the monitor, if you have space just for one line it won't print the other ones.
I'm not sure what you mean with the delay. It works fine in my world.
If you don't clear the screen the previous text will remain, so it will look really bad.
I'm not sure what you mean with the delay. It works fine in my world.
If you don't clear the screen the previous text will remain, so it will look really bad.
Posted 15 July 2012 - 03:34 AM
What i find to work for me with a 1x4 monitor is this:Each line is a different line in the monitor, if you have space just for one line it won't print the other ones.
I'm not sure what you mean with the delay. It works fine in my world.
If you don't clear the screen the previous text will remain, so it will look really bad.
mon = peripheral.wrap("back")
mon.setTextScale(5)
text = "Grey_M62 is awesome. "
pos = 10
while true do
mon.setCursorPos(pos, 1)
mon.write(text)
sleep(0.2)
if pos == -15 then
pos = 10
else
pos = pos - 1
end
end
the only problem now, is that the end of the line does not keep scrolling. what i want is the end of the text to still be partially visible when the beginning of the text re-appears. if I add 'mon.clear()' to the code right before 'mon.setCursorPos(pos, 1)' then the text disappears and waits a second or two before re-appearing. That is not what i want. can you edit MY code to fix this?Posted 15 July 2012 - 03:12 PM
Why dont you just ask northcode for the code? Im pretty sure they dont bite.
Posted 15 July 2012 - 03:53 PM
They use this http://www.computercraft.info/forums2/index.php?/topic/1942-marquee/page__hl__marquee__fromsearch__1Why dont you just ask northcode for the code? Im pretty sure they dont bite.