Here's the monitor code: http://pastebin.com/TW4QCW1T
My current problem is that it isn't writing to the advanced monitor that's to the right of the computer.
The monitor is 4x4 if that affects anything.
Could someone tell me what I'm doing wrong with this code please?
1
Could somebody help me with this monitor code?
Started by artman41, Apr 03 2015 09:09 PM
peripheral lua computer
4 replies to this topic
#1
Posted 03 April 2015 - 09:09 PM
#2
Posted 03 April 2015 - 09:43 PM
where you have monitor.write (and simular commands) you need to use your mon variable
for example lines 11 and 12 should be
for example lines 11 and 12 should be
mon.setCursorPos(x, y) mon.write(UserString)
#3
Posted 03 April 2015 - 09:46 PM
Ok, I believe I see the problem.
First off is your centerText function
1. At the start do
2. You have
Also remove the i= i + 1 in your monitorTimer function, it is unneeded as the for loop automatically increments it.
First off is your centerText function
1. At the start do
userString=tostring(userString)That way it will still work in case you give the function a number
2. You have
monitor.write(UserString)change that to
monitor.write(userString)3. While not really needed, make your x and y variables local, this is a good thing to practice.
Also remove the i= i + 1 in your monitorTimer function, it is unneeded as the for loop automatically increments it.
Edited by Quintuple Agent, 03 April 2015 - 09:47 PM.
#4
Posted 03 April 2015 - 09:53 PM
Quintuple Agent, on 03 April 2015 - 09:46 PM, said:
Ok, I believe I see the problem.
First off is your centerText function
1. At the start do
2. You have
Also remove the i= i + 1 in your monitorTimer function, it is unneeded as the for loop automatically increments it.
First off is your centerText function
1. At the start do
userString=tostring(userString)That way it will still work in case you give the function a number
2. You have
monitor.write(UserString)change that to
monitor.write(userString)3. While not really needed, make your x and y variables local, this is a good thing to practice.
Also remove the i= i + 1 in your monitorTimer function, it is unneeded as the for loop automatically increments it.
Ah, thanks for pointing that out, It works now
Nice to know that you don't need to manually increment i in For loops and thanks for pointing out the problem, I hadn't noticed that at all. Also, thanks for the tip about converting the input to a string, that'll most likely prevent future problems
#5
Posted 03 April 2015 - 09:57 PM
I dont looked to your code but you can write center with this function;
local function centerText(string) local mX, mY = mon.getSize(); x, y = term.getCursorPos(); x = mX / 2 x = x - string.len(string) / 2 term.setCursorPos(x, y) io.write(string) end
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users