Posted 13 December 2013 - 10:23 AM
Alright, so I'm trying to make a central touchscreen that has buttons for each thing I am wanting to control, and I am a bit of a noob. I am using wireless modems since RP2 left me without bundled cable. I want a singular modem from the central screen to send out specific messages according to which button is pressed. I keep getting an error that says " rednet : 11 : string expected" although I am sure that isn't the only thing wrong with my code. Any help is appreciated. Here is the code:
**Edit Here is the raw code. sorry about that, I'm a newcomer still learning the ropes.
txtsize = 1 –enter desired size of text
mdmside = right –enter side rednet modem is on
rednet.open(mdmside)
mon = peripheral.wrap(monside)
mon.setTextScale(txtsize)
mon.setBackgroundColor(colors.black)
mon.clear()
mon.setCursorPos(1,1)
w,h = mon.getSize()
write(w)
write(" x ")
write(h)
local button = {}
function properties(name, xmin, xmax, ymin, ymax, sendtoid)
button[name] = {}
button[name]["active"] = false
button[name][xmin] = xmin
button[name][xmax] = xmax
button[name][ymin] = ymin
button[name][ymax] = ymax
button[name][message] = message
end
– may need to insert toggle function here
function toggle()
if button["Engines"]["active"] == true then
rednet.broadcast(message)
else
rednet.broadcast("Engines Off")
print("Engines Off")
end
end–ends function toggle()
function ButtonName() –Where you can add more buttons
properties("Engines", 1, 10, 1, w, Engines)
end
function colorfill(text, color, bData)
–determines where buttons are located
mon.setBackgroundColor(color)
local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
for j = bData["ymin"], bData["ymax"] do
mon.setCursorPos(bData["xmin"], j)
if j == yspot then
for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) + 1 do
if k == xspot then
mon.write(text)
else
mon.write(" ")
end
end
else
for i = bData["xmin"], bData["xmax"] do
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
end
function screen()
local currColor
for name, data in pairs(buttons) do
local on = data["active"]
if on == true then
currColor = colors.lime
else
currColor = colors.red
fill(name, currColor, data) –may need to be colorfill
end
end
end
function checkxy(x, y)
for name, data in pairs(button) do
if y >= data["ymin"] and y <= data["ymax"] then
if x>= data["xmin"] and x <= data["xmax"] then
toggle(data["active"])
data["active"] = not data["active"]
print(name)
end
end
end
end
ButtonName()
while true do
mon.clear()
screen()
local e,side,x,y = os.pullEvent("monitor_touch")
print(x..":"..y)
checkxy(x,y)
sleep(.1)
end
So I think I've sorted that problem out, but now it says it has an "error comparing __le to nil" in the function checkxy(x, y) in the first IF statement. Heres the updated code:
txtsize = 1 –enter desired size of text
mdmside = right –enter side rednet modem is on
rednet.open("right")
mon = peripheral.wrap("top")
mon.setTextScale(1)
mon.setBackgroundColor(colors.black)
mon.clear()
mon.setCursorPos(1,1)
h,w = mon.getSize()
print(w.."x"..h)
local button = {}
function properties(name, xmin, xmax, ymin, ymax)
button[name] = {}
button[name]["active"] = false
button[name][xmin] = xmin
button[name][xmax] = xmax
button[name][ymin] = ymin
button[name][ymax] = ymax
–button[name][message] = message
end
function toggle()
if button["Engines"]["active"] == true then
rednet.broadcast("EnginesOn")
print("EnginesOn")
else
rednet.broadcast("EnginesOff")
print("Engines Off")
end
end–ends function toggle()
function ButtonName() –Where you can add more buttons
–properties("ButtonName", xmin, xmax, ymin, ymax)
properties("Engines", 1, 29, 1, 5)
end
function colorfill(text, color, bData)
–determines where buttons are located
mon.setBackgroundColor(color)
local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
for j = bData["ymin"], bData["ymax"] do
mon.setCursorPos(bData["xmin"], j)
if j == yspot then
for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) + 1 do
if k == xspot then
mon.write(text)
else
mon.write(" ")
end
end
else
for i = bData["xmin"], bData["xmax"] do
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
end
function screen()
local currColor
for name, data in pairs(button) do
local on = data["active"]
if on == true then
currColor = colors.lime
else
currColor = colors.red
–fill(name, currColor, data) –may need to be colorfill
end
end
end
function checkxy(x, y)
for name, data in pairs(button) do
if y >= data["ymin"] and y <= data["ymax"] then
if x>= data["xmin"] and x <= data["xmax"] then
toggle(data["active"])
data["active"] = not data["active"]
print(name)
end
end
end
end
ButtonName()
while true do
mon.clear()
screen()
local e,side,x,y = os.pullEvent("monitor_touch")
print(x..":"..y)
checkxy(x,y)
sleep(.1)
end
**Edit Here is the raw code. sorry about that, I'm a newcomer still learning the ropes.
Spoiler
monside = "top" –enter the side your monitor is ontxtsize = 1 –enter desired size of text
mdmside = right –enter side rednet modem is on
rednet.open(mdmside)
mon = peripheral.wrap(monside)
mon.setTextScale(txtsize)
mon.setBackgroundColor(colors.black)
mon.clear()
mon.setCursorPos(1,1)
w,h = mon.getSize()
write(w)
write(" x ")
write(h)
local button = {}
function properties(name, xmin, xmax, ymin, ymax, sendtoid)
button[name] = {}
button[name]["active"] = false
button[name][xmin] = xmin
button[name][xmax] = xmax
button[name][ymin] = ymin
button[name][ymax] = ymax
button[name][message] = message
end
– may need to insert toggle function here
function toggle()
if button["Engines"]["active"] == true then
rednet.broadcast(message)
else
rednet.broadcast("Engines Off")
print("Engines Off")
end
end–ends function toggle()
function ButtonName() –Where you can add more buttons
properties("Engines", 1, 10, 1, w, Engines)
end
function colorfill(text, color, bData)
–determines where buttons are located
mon.setBackgroundColor(color)
local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
for j = bData["ymin"], bData["ymax"] do
mon.setCursorPos(bData["xmin"], j)
if j == yspot then
for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) + 1 do
if k == xspot then
mon.write(text)
else
mon.write(" ")
end
end
else
for i = bData["xmin"], bData["xmax"] do
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
end
function screen()
local currColor
for name, data in pairs(buttons) do
local on = data["active"]
if on == true then
currColor = colors.lime
else
currColor = colors.red
fill(name, currColor, data) –may need to be colorfill
end
end
end
function checkxy(x, y)
for name, data in pairs(button) do
if y >= data["ymin"] and y <= data["ymax"] then
if x>= data["xmin"] and x <= data["xmax"] then
toggle(data["active"])
data["active"] = not data["active"]
print(name)
end
end
end
end
ButtonName()
while true do
mon.clear()
screen()
local e,side,x,y = os.pullEvent("monitor_touch")
print(x..":"..y)
checkxy(x,y)
sleep(.1)
end
So I think I've sorted that problem out, but now it says it has an "error comparing __le to nil" in the function checkxy(x, y) in the first IF statement. Heres the updated code:
Spoiler
monside = "top" –enter the side your monitor is ontxtsize = 1 –enter desired size of text
mdmside = right –enter side rednet modem is on
rednet.open("right")
mon = peripheral.wrap("top")
mon.setTextScale(1)
mon.setBackgroundColor(colors.black)
mon.clear()
mon.setCursorPos(1,1)
h,w = mon.getSize()
print(w.."x"..h)
local button = {}
function properties(name, xmin, xmax, ymin, ymax)
button[name] = {}
button[name]["active"] = false
button[name][xmin] = xmin
button[name][xmax] = xmax
button[name][ymin] = ymin
button[name][ymax] = ymax
–button[name][message] = message
end
function toggle()
if button["Engines"]["active"] == true then
rednet.broadcast("EnginesOn")
print("EnginesOn")
else
rednet.broadcast("EnginesOff")
print("Engines Off")
end
end–ends function toggle()
function ButtonName() –Where you can add more buttons
–properties("ButtonName", xmin, xmax, ymin, ymax)
properties("Engines", 1, 29, 1, 5)
end
function colorfill(text, color, bData)
–determines where buttons are located
mon.setBackgroundColor(color)
local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
for j = bData["ymin"], bData["ymax"] do
mon.setCursorPos(bData["xmin"], j)
if j == yspot then
for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) + 1 do
if k == xspot then
mon.write(text)
else
mon.write(" ")
end
end
else
for i = bData["xmin"], bData["xmax"] do
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
end
function screen()
local currColor
for name, data in pairs(button) do
local on = data["active"]
if on == true then
currColor = colors.lime
else
currColor = colors.red
–fill(name, currColor, data) –may need to be colorfill
end
end
end
function checkxy(x, y)
for name, data in pairs(button) do
if y >= data["ymin"] and y <= data["ymax"] then
if x>= data["xmin"] and x <= data["xmax"] then
toggle(data["active"])
data["active"] = not data["active"]
print(name)
end
end
end
end
ButtonName()
while true do
mon.clear()
screen()
local e,side,x,y = os.pullEvent("monitor_touch")
print(x..":"..y)
checkxy(x,y)
sleep(.1)
end
Edited on 13 December 2013 - 02:53 PM