Posted 25 March 2012 - 09:08 AM
Hey, im trying to combine some codes with my very basic Lua skills.
Its simply a door toggle, i found a code in here somewhere i tried to modify so i could use arrows instead of haveing to write it.
but it keeps failing on me.
problem:
it start fine, but whenever i try to use my arrows its puts "Select a door to toggle: (using UP/down arrows)" in between "—Door Controller—" and "——"..
Here is the code:
Its simply a door toggle, i found a code in here somewhere i tried to modify so i could use arrows instead of haveing to write it.
but it keeps failing on me.
problem:
it start fine, but whenever i try to use my arrows its puts "Select a door to toggle: (using UP/down arrows)" in between "—Door Controller—" and "——"..
Here is the code:
shell.run("clear");
local x, y =term.getCursorPos()
term.clearLine()
s = {colors.white, colors.red, colors.yellow};
o = {"Closed", "Closed", "Closed"};
sn = {"Door 1", "Door 2", "Door 3"};
cs = 1;
co = "closed";
master = 0;
while true do
shell.run("clear");
-
master = 0;
print("--------Door Controller-------\n");
print("------------------------------\n");
for i=1, 3 do
status = o[i];
if(o[i] == "Open") then
status = status.." ";
master = master + s[i];
end
rs.setBundledOutput("left", master);
print(i.." - "..sn[i].." : "..status);
end
sValid = true;
while sValid do
write("\nSelect a door to toggle: (using UP/down arrows) ");
term.setCursorPos(x, y)
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent()
end
if b == 200 and cs == 3 then
cs=2
else
if b == 200 and cs = 2 then
cs=1
else
if b == 208 and cs = 1 then
cs=2
else
if b == 208 and cs = 2 then
cs=3
if b == 57 then
co=o[cs];
if(co == "Open") then
o[cs] = "Closed";
else
o[cs] = "Open";
end
end
end
end
end
end
end
end