Posted 17 August 2015 - 04:50 PM
Hello, first time poster here.
I'm trying to adapt the example program that's one the Touchpoint API thread to draw the buttons in a window that's parented by the main monitor. I'm able to get the buttons to draw sucessfully where I want them, but for some reason I can't get them to toggle when they are place on the monitor.
I know I can't term.redirect directly to the window, so I've been trying to redirect to the window first, then leaving touchpoint.new() blank so it uses the current terminal, however, this doesn't seem to be working.
os.loadAPI("touchpoint")
mon = peripheral.wrap("left")
mon.clear()
win = window.create(mon, 4, 4, 20, 20, true)
term.redirect(win)
–# intialize a new button set
local t = touchpoint.new()
–# add two buttons
t:add("left", nil, 3, 3, 9, 8, colors.blue, colors.lime)
t:add("right", nil, 12, 3, 18, 8, colors.blue, colors.lime)
–# draw the buttons
t:draw()
while true do
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
– –# p1 will be "left" or "right", since those are the button labels
– –# toggle the button that was clicked.
t:toggleButton(p1)
end
end
If someone could point out what's wrong with my code or provide an alternate solution I'd be most grateful. I've spent more time than I'd like to admit experiment and searching for solutions online but have not been sucessful. Being relatively new to Lua doesn't help either. =/
In case anyone is wondering, I'm using window term objects because I'm trying to use the buttons to intgrate with a background image (representing my reactor and turbines) for a control program, if that narrows down solutions any. Thanks in advanced.
I'm trying to adapt the example program that's one the Touchpoint API thread to draw the buttons in a window that's parented by the main monitor. I'm able to get the buttons to draw sucessfully where I want them, but for some reason I can't get them to toggle when they are place on the monitor.
I know I can't term.redirect directly to the window, so I've been trying to redirect to the window first, then leaving touchpoint.new() blank so it uses the current terminal, however, this doesn't seem to be working.
Spoiler
–# load the touchpoint APIos.loadAPI("touchpoint")
mon = peripheral.wrap("left")
mon.clear()
win = window.create(mon, 4, 4, 20, 20, true)
term.redirect(win)
–# intialize a new button set
local t = touchpoint.new()
–# add two buttons
t:add("left", nil, 3, 3, 9, 8, colors.blue, colors.lime)
t:add("right", nil, 12, 3, 18, 8, colors.blue, colors.lime)
–# draw the buttons
t:draw()
while true do
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
– –# p1 will be "left" or "right", since those are the button labels
– –# toggle the button that was clicked.
t:toggleButton(p1)
end
end
If someone could point out what's wrong with my code or provide an alternate solution I'd be most grateful. I've spent more time than I'd like to admit experiment and searching for solutions online but have not been sucessful. Being relatively new to Lua doesn't help either. =/
In case anyone is wondering, I'm using window term objects because I'm trying to use the buttons to intgrate with a background image (representing my reactor and turbines) for a control program, if that narrows down solutions any. Thanks in advanced.