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

Monitor programming help?

Started by Levaru, 15 August 2012 - 09:32 AM
Levaru #1
Posted 15 August 2012 - 11:32 AM
I tried to set up a monitor for the first time with the: mon = peripheral.wrap() command

My problem was that i had to type a new command for every line.

Example:
Hello!
How its going?
Anything new?

To get this text to display i had to write it like that:

mon.setcursorpos(1,1)
mon.write("Hello!")
mon.setcursorpos(1,2)
mon.write("How its going?")
mon.setcursorpos(1,3)
mon,write("anything new?)

Now if i wanted to write a BIG text it would take ages to type all this in,
Isnt there a way to type it in like that?

mon.setcursorpos(1,1)
mon.write("Hello!
How its going?
Anything new?")

Also is there a way to stop the text from going over the boundaries of the monitor? Like if its too long? Like stop at the most right border of the monitor and continue in the next line?

Thanks in advance!
timyo24 #2
Posted 15 August 2012 - 07:29 PM
Ok, you made this much harder than it actually is! :(/>/> I'm new to coding, but i have gotten alot of good advice from the people on here, so lemme see if i can wirte up suttin for you :)/>/>
Cranium #3
Posted 15 August 2012 - 07:30 PM
Since it's a write command, the next write picks up where the las left off. You would have to either use some tables to print out the lines(which is a pain), or you would just need to specify the monitor x,y before each new line.
OmegaVest #4
Posted 15 August 2012 - 08:11 PM

function monPrint (mon1, whiteout[])
   local monX, monY = mon.getCursorPos()

   for local i = 1, #whiteout do
	  mon1.write(whiteout[i])
	  monY+1
	  mon1.setCursorPos(monX, monY)
   end
end

Put this at the top of your program, use this to print. Automatically adds a line at the end. Could also use


whiteout[i] = whiteout[i] .. " n"
mon1.write(whiteout)

and just skip the setCursorPos.





EDIT:

About not going over. That's a little more complicated.


function monBreak (mon1, whiteout[])
   local monX, monY = mon1.getSize()
   local whitebreak = {}
   j = 1
   for i = 1, #whiteout do
      local stor = 1
      while true do
         if string.len(whiteout[i]) > monX then
            whitebreak[j] = string.sub(whiteout[i], stor, monX+stor-1)
            j = j+1
            stor = stor +1
         else
             whitebreak[j] = string.sub(whiteout[i], stor, string.len(whiteout[i]))
             j = j+1
             break
         end
      end
   end

   return whitebreak
end


That function returns a table (Or, should). You might be able to use these two functions together (ie. monPrint(mon, monBreak(stringers))) I don't know, though.