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

Need Help With Odd Script

Started by TylerTharp, 21 July 2013 - 10:52 PM
TylerTharp #1
Posted 22 July 2013 - 12:52 AM
I have another topic related to this program, but the purpose of that thread has been accomplished. I now need help changing the textscale, color, and background color for the monitor. It also has random characters that show up after the message. Can anyone help me out?

Here is the code.

scroll = 12
speed = 0.2
text = "Welome"
w,h = term.getSize()
posTexty = math.floor(h/2 + scroll/1.5)
posTextx = math.floor(w/2+12)
function vertical(text, lines, a, xpos, ypos)
  for b = lines,1, -1 do
		  term.setCursorPos(xpos, ypos-(b+1))
		  if a-b < string.len(text)+1 and a-b > 0 then
		    print(string.sub( text, a-b, a-b ))
		  else print(" ")
		  end
  end
end
scroll = 12
speed = 0.2
w,h = term.getSize()
posTexty = math.floor(h/2 + scroll/1.5)
posTextx = math.floor(w/2+12)
function vertical(text, lines, a, xpos, ypos)
  for b = lines,1, -1 do
		  term.setCursorPos(xpos, ypos-(b+1))
  
		  if a-b < string.len(text)+1 and a-b > 0 then
		    print(string.sub( text, a-b, a-b ))
		  else print(" ")
		  end
  end
end
while true do
term.redirect( peripheral.wrap( "right" ) )
term.clear()
for a = 1,string.len(text)+scroll+1 do
sleep(speed)
vertical(text, scroll, a, posTextx, posTexty)
end
term.restore()
end
Grim Reaper #2
Posted 22 July 2013 - 12:57 AM
Could you specify your problem? You need help setting things on the monitor?

Look here.
TylerTharp #3
Posted 22 July 2013 - 01:02 AM
I dont know where to put the textscale, color, and background color. And then their is that problem with some of the characters repeating when the text is displayed on the monitor.
MR_nesquick #4
Posted 22 July 2013 - 01:52 AM
the line over 'while true do'.

is this the vertical scrolling program? why not use


Text = {
"H",
"e",
"l",
"l",
"o",
}
mon = peripheral.wrap("right")
mon.setBackgroundColor(colours.red)
mon.setTextColor(colours.blue)
mon.setTextSize(3)
mon.clear()
wScreen, hScreen = mon.getSize()
function Vertical()
for i = -#Text,hScreen do
	  for t = 1,#Text do
		mon.setCursorPos(wScreen/2,i+t)
		mon.write(Text[t])
	  end
   mon.setCursorPos(wScreen/2,i)
   sleep(.2)
   mon.clear()
  end
end
while true do
Vertical()
end
TylerTharp #5
Posted 22 July 2013 - 02:10 AM
That worked great! How would I go about making it scroll from bottom to top though?
MR_nesquick #6
Posted 22 July 2013 - 02:15 AM

Text = {
"H",
"e",
"l",
"l",
"o",
}
mon = peripheral.wrap("right")
mon.setBackgroundColor(colours.red)
mon.setTextColor(colours.blue)
mon.setTextSize(3)
mon.clear()
wScreen, hScreen = mon.getSize()
function Vertical()

--for i = -#Text,hScreen do	 <---- use this to scroll down
for i = -hScreen,#Text do	<---- and this to scroll up

		  for t = 1,#Text do

				--mon.setCursorPos(wScreen/2,i+t)  <-- change to negative 'i' to scroll up and positive 'i' to scroll down
				mon.setCursorPos(wScreen/2,-i+t)

				mon.write(Text[t])
		  end
   mon.setCursorPos(wScreen/2,i)   --< and you can remove this one
   sleep(.2)
   mon.clear()
  end
end
while true do
Vertical()
end
TylerTharp #7
Posted 22 July 2013 - 01:37 PM
Thanks!
albrat #8
Posted 23 July 2013 - 06:55 AM
I have another topic related to this program, but the purpose of that thread has been accomplished. I now need help changing the textscale, color, and background color for the monitor. It also has random characters that show up after the message. Can anyone help me out?

Here is the code.
Spoiler

scroll = 12
speed = 0.2
text = "Welome"
w,h = term.getSize()
posTexty = math.floor(h/2 + scroll/1.5)
posTextx = math.floor(w/2+12)
function vertical(text, lines, a, xpos, ypos)
  for b = lines,1, -1 do
		  term.setCursorPos(xpos, ypos-(b+1))
		  if a-b &amp;lt; string.len(text)+1 and a-b &amp;gt; 0 then
			print(string.sub( text, a-b, a-b ))
		  else print(" ")
		  end
  end
end
scroll = 12
speed = 0.2
w,h = term.getSize()
posTexty = math.floor(h/2 + scroll/1.5)
posTextx = math.floor(w/2+12)
function vertical(text, lines, a, xpos, ypos)
  for b = lines,1, -1 do
		  term.setCursorPos(xpos, ypos-(b+1))

		  if a-b &amp;lt; string.len(text)+1 and a-b &amp;gt; 0 then
			print(string.sub( text, a-b, a-b ))
		  else print(" ")
		  end
  end
end
while true do
term.redirect( peripheral.wrap( "right" ) )
term.clear()
for a = 1,string.len(text)+scroll+1 do
sleep(speed)
vertical(text, scroll, a, posTextx, posTexty)
end
term.restore()
end

I would like to point out you pasted the function vertical twice there… That will cause a problem. Also on the other thread where this code is posted, I made changes that fixed the problem, The program is reading the size of the terminal and not the monitor. They were my mistakes. * I also fixed them and made it work properly again.

To change the size of the text on the monitor you would need "monitor.setTextScale(2)" The program I wrote has been modified since so I could make it a Message of the day board. … Editable text

here is what I made…
term.clear()  -- start by clearing the terminal
mon = peripheral.wrap("right")  -- wrap our monitor to the right
mon.setTextScale(2.5) -- set our text scale on the monitor to x.x ( 1 to 5.5 limits )
scroll = 8 -- we are showing 6 characters on the screen on our upwards scroll...
speed = 0.5 -- length of sleep 
w,h = mon.getSize() -- get screen size
posTexty = math.floor( h/2 + scroll/1.5 ) -- some strange math but /2 gave a odd effect so /1.5 works better
posTextx = math.floor( w/2 ) -- our x pos on the screen (i want a center text)

-- our Vertical print function

function vertical(text, lines, a, xpos, ypos)  -- text, number of lines, our pos in the text, x loc, y loc.
  for b = lines,1, -1 do  -- for each line of our scroll...
      mon.setCursorPos(xpos, ypos-(b+1)) -- set pos on screen
      if a-b < string.len(text)+1 and a-b > 0 then  -- if we have text to display from our string...
        mon.write(string.sub( text, a-b, a-b ))  -- write that text to the screen.
      else mon.clearLine()  -- otherwise just clear the line so we don't leave a text trail.
      end -- end the if a-b ...
  end -- end the for b = ...
end -- return from function

-- setup screen colors

mon.setBackgroundColor(colors.white) -- setup screen color
mon.setTextColor(colors.black)  -- setup text color
mon.clear()  -- clear the monitor to apply the settings.
-- Main program

while true do
e={} -- setup our events table
  term.setCursorPos(1,2) -- Position for us to write the message
  term.clearLine() -- Clear the line of old text just incase.
  write("Input Message : ")  -- ask user to input the message to display
  text = read()  -- get the message they type
  if text == "" then   -- if nothing typed then use default message
    text = "MOTD - Welcome!" -- our message default
  end
  term.setCursorPos(1,2) -- location of our last message
  term.clearLine() -- clear that one line of all text.
  term.setCursorPos(43,19) -- where we want our exit command for new text to be inserted
  term.clearLine() -- clear the line of old text
  term.write("2 to exit") -- Print the key to press to enter the new text (2)
loop = true  -- we want our text to scroll untill we stop it with key 2

  while loop do  -- while loop == true we repeat this loop
    for a = 1,string.len(text)+scroll+1 do  -- do our string length + scroll + 1 (so the last char is not missed)
--      sleep(speed) -- the speed of our scroll.
      vertical(text, scroll, a, posTextx, posTexty) -- call the function.
      os.startTimer(speed)  -- the speed of our scroll and our escape key capture
      e = {os.pullEvent()}  -- pull events as a table
      if e[2] == 3 then  -- if the value of event is 3 ( key press 2 )  then 
	  loop = false -- we break the while loop .
	  mon.clear() -- clear the monitor
	  break -- break the for loop and return to requesting a new message
	  end
    end
  end
  sleep(1) -- we pause to let the stack empty.
end
-- EOF!!