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

Monitor Scrolling?

Started by Grey_M62, 14 July 2012 - 11:20 PM
Grey_M62 #1
Posted 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.
Grey_M62 #2
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?
Sxw #3
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
Sxw #4
Posted 15 July 2012 - 01:52 AM
So you shorten the delay to 0.1 or lower?I know ur reading this, mystic.
Grey_M62 #5
Posted 15 July 2012 - 01:57 AM
So you shorten the delay to 0.1 or lower?I know ur reading this, mystic.
that makes the text go by faster, but doesn't decrease the delay between the text.
MysticT #6
Posted 15 July 2012 - 01:57 AM
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)

So you shorten the delay to 0.1 or lower?I know ur reading this, mystic.
:P/>/>
I was writing this post.
Grey_M62 #7
Posted 15 July 2012 - 02:03 AM
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)

So you shorten the delay to 0.1 or lower?I know ur reading this, mystic.
:P/>/>
I was writing this post.
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.
MysticT #8
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.
Grey_M62 #9
Posted 15 July 2012 - 03:34 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.
What i find to work for me with a 1x4 monitor is this:

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?
Sxw #10
Posted 15 July 2012 - 03:12 PM
Why dont you just ask northcode for the code? Im pretty sure they dont bite.
1lann #11
Posted 15 July 2012 - 03:53 PM
Why dont you just ask northcode for the code? Im pretty sure they dont bite.
They use this http://www.computercraft.info/forums2/index.php?/topic/1942-marquee/page__hl__marquee__fromsearch__1