First of all, to make sure there's actually a monitor attached to the computer, and also making it easier for you I'd suggest you'd check out
peripheral.find
Example
local mon = peripheral.find( "monitor" )
if not monitor then --# Check if the mon variable is nil or not
error( "No monitor attached!", 0 ) --# If it was, then we display an error
end
I know this may not be the case for you, but it may still be handy and save you trouble in the future.
Another suggestion I'd recommend would be to use tables, where it would be easier for you to store all your buttons. So if your basic "drawing" and "handling" function is working as it should, all you have todo is look at the table and fix any problems there.
Here's an example of how you'd create a table of buttons and draw them, it doesn't just make it easier for you, but it also helps shorten your code a lot.
So how would you check if any of these buttons have been clicked/touched? Well that's pretty easy, we'll do the same when drawing the buttons, we'll loop through all of them.
Oh, and another suggestion, use code tags when posting code here on the forums
[
code] code here [/
code]
While this has nothing to do with actual coding, it helps people here to help you faster, as it makes it easier to read.
I've also seen this in your code
if x > 1 and x < 10 and y == 6 then
mon.setCursorPos( 1, 6 )
...
end
I believe you want to be able to touch at the x position 1 and 10, but the way you're checking the coordinates it checks if it's any number between them( 2-9 ), to solve this you'd want to use
>= and
<=
I hope this was helpful, and if you have any questions about any of the code then please feel free to ask.
Edited by TheOddByte, 21 June 2015 - 11:08 PM.