9 posts
Posted 03 April 2015 - 10:09 PM
Here's the monitor code:
http://pastebin.com/TW4QCW1TMy 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?
2427 posts
Location
UK
Posted 03 April 2015 - 10: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
mon.setCursorPos(x, y)
mon.write(UserString)
113 posts
Location
This page
Posted 03 April 2015 - 10:46 PM
Ok, I believe I see the problem.
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 on 03 April 2015 - 08:47 PM
9 posts
Posted 03 April 2015 - 10:53 PM
Ok, I believe I see the problem.
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 :D/>
10 posts
Location
Turkey
Posted 03 April 2015 - 10: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