Posted 12 May 2015 - 12:51 AM
Trying to write a simple Open/Close door program with touch screen monitors. I was hoping to make it show a green box with white letters saying "open" when the door is closed, then when the door is open the button would be red and say "close". Simple right? Well I keep getting java thrown errors. I'm trying to set up both monitors to one computer (one monitor per side of the door) and the best way to do that would be with networking cables. So I've included a picture of my setup so you guys can understand. Thank you in advance, I'm new to Lua and Computercraft but not to programming so I will most likely be able to understand any code that you guys may right. Thanks!
My setup photo:
My code:
My setup photo:
My code:
Spoiler
--Wrap Monitors
local om = peripheral.wrap("monitor_0") --"om" is "Outside Monitor"
local im = peripheral.wrap("monitor_1") --"im" is "Inside Monitor"
--Set Colors
local bkg = colors.black
local txt = colors.white
local btn_o = colors.red
local btn_c = colors.green
--Set Button Text
local txt_o = "Close"
local txt_c = "Open"
--Set button state
local state = 0 --0 = open 1 = closed
while true do
--Set what color & text the button is at state
if state==0 then
local scolor=btn_o
local stext=txt_o
else
local scolor=btn_c
local stext=txt_c
end
--Draw Button
paintutils.drawFilledBox(2,2,6,6,scolor)
--Draw Button Text
om.setCursorPos(3,4)
im.setCursorPos(3,4)
om.write(stext)
im.write(stext)
--Detect click
event, side, x, y = os.pullEvent("monitor_touch")
if x>2 and x<6 and y>2 and y<6 then
if state==0 then
state=1
else
state=0
end
end
om.clear()
im.clear()
end