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

Text on monitor

Started by MrR0ket0, 29 July 2012 - 05:39 PM
MrR0ket0 #1
Posted 29 July 2012 - 07:39 PM
Hello gentleman,

i have following problem:
tried to figure out a way of displaying a text on monitor (monitor size is 6x5 blocks - in multiplayer)
found in this forum following:

local tText = {
"First line", – you can change the lines here
"Second line",
"Some more",
"lines here"
– and you can add more if you want, just don't forget to put the commas (,) at the end of the lines (except for the last one)
}
local sSide = "left"
local nTextSize = 1 – change the text size here (from 1 to 5)

local function printCenter(mon, t)
local w, h = mon.getSize()
local y = math.floor((h / 2) - (#t / 2)) - 1
for i, line in ipairs(t) do
local x = math.floor((w / 2) - (#line / 2))
mon.setCursorPos(x, y + i)
mon.write(line)
end
end

local mon = peripheral.wrap(sSide)
mon.setTextScale(nTextSize)
printCenter(mon, tText)

Original topic http://www.computerc...age-on-monitor/

Apperenty this doenst work

How i try to use it: I open up the computer, type in: edit start, enter the sourcecode from above - i hit save. Then ill type in "Start" it tells me " start:20: attempt to index ? (a nil value)"

What iam doing wrong and how iam suppose to make the text appear in the monitor with multiple lines?
Also if possible i want the first line in a differnt Size than the rest and eveything needs to be center lined

thanks in advance
(just to mention ive tried this in singleplayer but ill need it to work in Multiplayer to display a certain text on the monitor)
Cranium #2
Posted 29 July 2012 - 08:24 PM
Did you select the correct monitor side? where it says local sSide = "left", is that the side your monitor is on?
MrR0ket0 #3
Posted 29 July 2012 - 08:28 PM
uhm the monitor is to the right side of the computer, but would that be enought to not have this script running? besides is the script and the way how i use it correct?
and what does "start:20: attempt to index ? (a nil value)" means?

i know questions questions questions …

sry, i have little experience with c++ lua is new to me and i have to get used to it :ph34r:/>/>

p.s. i made it work it DOES matter where your monitor is located, know i only need to figure out how to have the very fist line in a bigger size than the rest
MrR0ket0 #4
Posted 29 July 2012 - 09:27 PM
again posting because this is so frustrating, it works in singleplayer but in multiplayer ill get the msg:" start:12: attempt to call nil"
i dont understand why would it work fine in single but not in multiplayer? and no, servers comptercraft is not limited …
ChiknNuggets #5
Posted 29 July 2012 - 09:29 PM
The problem is that your ttrying to get the size of a thing that u havent defined yet move local mon = peripheral.wrap(sSide) to the top of the script
MrR0ket0 #6
Posted 29 July 2012 - 09:32 PM
First off thx for the help i got it work now, but one problem left how can i change now the very fist text line in a differnt textsize than the rest?
Pugz #7
Posted 29 July 2012 - 09:52 PM
once you have called the mon = peripheral.wrap(sSide) you can use the mon part to define the size and position, try using mon.setCursorPos(1, 1) to set the position of the cursor to the top left (I'm not 100% sure that you should leave that to the term. API if your using the redirect method) give it a try though. With the size you can use mon.setTextScale(1) any number between 1-5 (must not be 0).

If you have more problems just Google the codes I've shown to learn a little more :)/>/> or checkout the ComputerCraft wiki API you should read up (if you haven't already) about the term. and peripheral. API's

Hope this helps :ph34r:/>/>
Cranium #8
Posted 29 July 2012 - 09:53 PM
Unfortunately you can't. You can only define one text size for one monitor. Maybe in the future they'll add more, but right now, you can't.
MrR0ket0 #9
Posted 29 July 2012 - 10:23 PM
once again thx for your help guys :ph34r:/>/> :)/>/>
its fine for now i guess.
I will study this forum more closely + wiki might improve my skills in computercraft