Posted 15 January 2013 - 11:01 AM
What is wrong in this code? (Problem is with Drzwi(door) it don't works)
It's mostly in Polish if you wont to know ;)/>
@Edit
Computer controling drzwi(door) code
Computer controling Tarzca(shiled) code
local charSelected = ">"
local charNotSelected = " "
local optionLength = 42
local configPath = "Database/config"
local logoFile = "Config/test.nfp"
local optionOnTextColor = colors.lime
local optionOffTextColor = colors.red
local keyUp = 200
local keyDown = 208
local keyEnter = 28
local keyQuit = 16
local options = { -- list of options
[1] = {name = "a", title = "Drzwi", value = "ON", ["type"] = "toggle", valueOn = "ON", valueOff = "OFF"},
[2] = {name = "b", title = "Tarcza", value = "ON", ["type"] = "toggle", valueOn = "ON", valueOff = "OFF"},
--[3] = {name = "c", title = "System", value = "ON", ["type"] = "togglesleep", valueOn = "ON", valueOff = "Restartowanie"},
}
local selected = 1 -- default option
local running = true
-- HELPER FUNCTIONS
local function redrawMenu()
local termWidth, termHeight = term.getSize()
local startY = 2
term.setBackgroundColor(colors.white)
for i=1, #options, 1 do
term.setTextColor(colors.yellow)
term.setCursorPos( 2, startY + i - 1 )
if selected == i then write(charSelected) term.setTextColor(colors.orange)
else write(charNotSelected) term.setTextColor(colors.cyan) end
write( options[i].title )
write( string.rep( " ", optionLength - string.len( options[i].title ) ) )
if options[i]["type"] == "toggle" then
if options[i].value == options[i].valueOn then
term.setTextColor(optionOnTextColor)
else
term.setTextColor(optionOffTextColor)
end
end
write( tostring(options[i].value) )
write( string.rep( " ", termWidth - optionLength - string.len(options[i].value) - 3 ) )
end
term.setCursorPos(2,18)
write( string.rep( " ", termWidth - 2 ) )
end
-- program
term.clear()
local canMove = true
while running do
rednet.open("bottom")
redrawMenu()
canMove = options[selected]["type"] == "toggle" or
( (options[selected]["type"] == "key") and (options[selected].value ~= "_") )
if options[1].value == "ON" then rednet.send(4, "ON") mon.clear() mon.setCursorPos(1,1) mon.setTextColor(colors.lime) mon.setTextScale(2) mon.write("Drzwi: On") elseif options[1].value == "OFF" then rednet.send(4, "OFF") mon.clear() mon.setCursorPos(1,1) mon.setTextColor(colors.red) mon.setTextScale(2) mon.write("Drzwi: Off") end
if options[2].value == "ON" then rednet.send(6, "ON") mon.clear() mon.setCursorPos(1,2) mon.setTextColor(colors.lime) mon.setTextScale(2) mon.write("Tarcza: On") elseif options[2].value == "OFF" then rednet.send(6, "OFF") mon.clear() mon.setCursorPos(1,2) mon.setTextColor(colors.red) mon.setTextScale(2) mon.write("Tarcza: Off") end
event, p1 = os.pullEvent()
if event == "key" then
if p1 == keyDown and canMove then
if selected == #options then selected = 1
else selected = selected + 1 end
elseif p1 == keyUp and canMove then
if selected == 1 then selected = #options
else selected = selected - 1
end
elseif p1 == keyEnter and canMove then
if options[selected]["type"] == "toggle" then
if options[selected].value == options[selected].valueOn then
options[selected].value = options[selected].valueOff
else
options[selected].value = options[selected].valueOn
end
elseif p1 == 16 then
running = false
end
end
end -- while running
It's mostly in Polish if you wont to know ;)/>
@Edit
Computer controling drzwi(door) code
while true do
term.setCursorPos(1,1)
term.clearLine()
printC("MibacMFFSOs", colors.yellow)
rednet.open("bottom")
e, p1, p2 = os.pullEvent("rednet_message")
if p1 == 5 and p2 == "ON" then
rs.setOutput("top", true)
term.clear()
printCentered("Force: On", 2, colors.lime)
elseif p1 == 5 and p2 == "OFF" then
rs.setOutput("top", false)
term.clear()
printCentered("Force: Off", 2, colors.red)
elseif p1 == 5 and p2 == "Reboot" then os.reboot()
end
sleep(0)
end
Computer controling Tarzca(shiled) code
while true do
term.setCursorPos(1,1)
term.clearLine()
printC("MibacMFFSOs", colors.yellow)
rednet.open("bottom")
e, p1, p2 = os.pullEvent("rednet_message")
if p1 == 5 and p2 == "ON" then
rs.setOutput("top", true)
term.clear()
printCentered("Force: On", 2, colors.lime)
elseif p1 == 5 and p2 == "OFF" then
rs.setOutput("top", false)
term.clear()
printCentered("Force: Off", 2, colors.red)
elseif p1 == 5 and p2 == "Reboot" then os.reboot()
end
sleep(0)
end