Posted 31 January 2013 - 05:10 AM
Hello! The basic idea of this is to have a touchscreen where u'll push 4 buttons and each one will send a bundledoutput color then go into an active state, once it's clicked again it will stop sending signal.
I've got the next code:
I've got it from a Direwolf20 video, each time I try to change the size of the buttons or adding one more to the table, it messes up the touchscreen, so, i think it has something to do with where the touchscreen is showing the buttons and where is recognicing the click to change the state and send the rs signal. I can add more buttons with custom names and colors but the touchscreen won't chage them into green if i click on them as it does with the other ones. Wich part should i edit to get it working? I have to change the size in other place than the filltable function?
Please help, thanks!
I've got the next code:
llocal term = peripheral.wrap("top")
term.setTextScale(1.5)
local mob={}
function setTable(name, freq, xmin, xmax, ymin, ymax)
mob[name] = {}
mob[name]["freq"] = freq
mob[name]["active"] = false
mob[name]["xmin"] = xmin
mob[name]["ymin"] = ymin
mob[name]["xmax"] = xmax
mob[name]["ymax"] = ymax
end
function fillTable()
setTable("Chicken", colors.red, 17, 24, 2, 3)
setTable("Cow", colors.white, 17, 20, 6, 7)
setTable("Pig", colors.yellow, 17, 20, 4, 5)
end
function fill(x,y,color,text)
term.setBackgroundColor(color)
term.setCursorPos(x,y)
term.write(text)
term.setBackgroundColor(colors.black)
end
function screen()
local y = 2
local currColor
for name,data in pairs(mob) do
local on = data["active"]
if on == true then currColor = colors.lime else currColor = colors.red end
fill(17,y,currColor, name)
y = y+2
end
end
function checkxy(x, y)
for name, data in pairs(mob) do
if y>=data["ymin"] and y <= data["ymax"] then
if x>=data["xmin"] and x<= data["xmax"] then
data["active"] = not data["active"]
print(name)
end
end
end
end
function setWire()
local wire = 0
for name, data in pairs(mob) do
if data["active"] == false then
wire = colors.combine(wire, data["freq"])
end
end
redstone.setBundledOutput("bottom", wire)
end
fillTable()
setWire()
while true do
term.clear()
screen()
-- fill(17,2,colors.lime, "Chicken")
local e,side,x,y = os.pullEvent("monitor_touch")
print(x..":"..y)
checkxy(x,y)
setWire()
sleep(.1)
end
I've got it from a Direwolf20 video, each time I try to change the size of the buttons or adding one more to the table, it messes up the touchscreen, so, i think it has something to do with where the touchscreen is showing the buttons and where is recognicing the click to change the state and send the rs signal. I can add more buttons with custom names and colors but the touchscreen won't chage them into green if i click on them as it does with the other ones. Wich part should i edit to get it working? I have to change the size in other place than the filltable function?
Please help, thanks!