Posted 05 February 2014 - 07:00 PM
I wrote up a quick button program to test how I wanted to implement it in my main program and it is acting oddly. The first time I run the program it prints the button in the wrong position. The second time it prints the button in the correct position.
The code http://pastebin.com/tq75PA7H
And here is a picture for clarification. The red button is where it prints the first time the program is run. The second time it prints where the green button is and continues working after that. I have also tried it with different sized screens and it prints in the wrong position the first time no matter what the size. Also, the button changes color correctly no matter which position it is in.
The code http://pastebin.com/tq75PA7H
Spoiler
local m = peripheral.wrap("right")
local monx, mony = m.getSize()
local button = {}
button.label = "Manual Override"
button.x = monx/2 - #button.label/2
button.y = mony/2
button.w = #button.label+2
button.h = 3
button.state = true
m.setTextScale(.5)
local function drawButton(b, color)
m.setBackgroundColor(color)
for row = 1,b.h do
m.setCursorPos(b.x,b.y+row-1)
m.write(string.rep(" ", b.w))
end
m.setCursorPos(b.x+1, b.y+1)
m.write(b.label)
end
drawButton(button, colors.lime)
while true do
local event, x, y = os.pullEvent()
if event == "monitor_touch" then
if button.state == true then
button.state = false
drawButton(button, colors.red)
elseif button.state == false then
button.state = true
drawButton(button, colors.lime)
end
end
end
And here is a picture for clarification. The red button is where it prints the first time the program is run. The second time it prints where the green button is and continues working after that. I have also tried it with different sized screens and it prints in the wrong position the first time no matter what the size. Also, the button changes color correctly no matter which position it is in.