Posted 09 April 2012 - 04:11 AM
Hello there!
I'm still learning lua and I like to play around with all the Redpower stuff as well as Computercraft.
So I made a program which lets you easily control all the colors on every side.
It's usefull for uncomplicated Redpower circuit testing and maybe even controlling…
if anyone has suggestions how I can improve the code please let me know! I had some problems coding it and couldn't always find satisfying solutions.
here's the code:
local currentY = 1
local current=1
color="magenta"
whileside = 1
sideout1= "back"
sideout2= "left"
sideout3= "right"
sideout4= "front"
sideout5= "bottom"
sideout6= "top"
while whileside==1 do
term.clear()
term.setCursorPos(1,1)
print("enter bundled cable output side:")
currentside=read()
if currentside== sideout1 then
whileside=2
elseif currentside== sideout2 then
whileside=2
elseif currentside== sideout3 then
whileside=2
elseif currentside== sideout4 then
whileside=2
elseif currentside== sideout5 then
whileside=2
elseif currentside== sideout6 then
whileside=2
end
end
function drawCursor()
term.setCursorPos(currentX, currentY)
write("["..color.."]")
end
function side()
while whileside==2 do
term.clear()
term.setCursorPos(1,1)
write("current side active: "..currentside)
term.setCursorPos(1,3)
print("which side do you want")
print("to be the new output side?")
currentside = read()
if currentside== sideout1 then
whileside=3
elseif currentside== sideout2 then
whileside=3
elseif currentside== sideout3 then
whileside=3
elseif currentside== sideout4 then
whileside=3
elseif currentside== sideout5 then
whileside=3
elseif currentside== sideout6 then
whileside=3
end
end
end
function quit()
term.clear()
term.setCursorPos(2,1)
print("do you really want to quit?")
local n=1
while true do
term.setCursorPos(2,2)
if n==1 then write(">YES< NO ") else write (" YES >NO<") end
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent() end
if b==203 and n==2 then n=1 end
if b==205 and n==1 then n=2 end
if b==28 then print("") break end
end
if n==1 then os.reboot() end
if n==2 then return false end
end
function writecolors()
term.clear()
term.setCursorPos(2,1)
write("magenta")
term.setCursorPos(13,1)
write("orange")
term.setCursorPos(24,1)
write("green")
term.setCursorPos(35,1)
print("red")
term.setCursorPos(2,2)
write("black")
term.setCursorPos(13,2)
write("gray")
term.setCursorPos(24,2)
write("l-gray")
term.setCursorPos(35,2)
write("cyan")
term.setCursorPos(2,3)
write("pink")
term.setCursorPos(13,3)
write("lime")
term.setCursorPos(24,3)
write("purple")
term.setCursorPos(35,3)
write("yellow")
term.setCursorPos(2,4)
write("blue")
term.setCursorPos(13,4)
write("brown")
term.setCursorPos(24,4)
write("l-blue")
term.setCursorPos(35,4)
write("white")
term.setCursorPos(2,6)
write("side")
term.setCursorPos(13,6)
write("quit")
term.setCursorPos(1,13)
write("side: "..currentside)
end
while true do –/////////while//////////
writecolors()
drawCursor()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then –up
if currentY >= 2 then
currentY = currentY -1
current= current-4
if currentY==5 then
currentY= currentY-1
end
end
elseif key == 31 or key == 208 then –down
if currentY <=5 then
currentY = currentY +1
current = current+4
if currentY == 5 then
currentY = currentY+1
end
if currentY == 4 and currentX== 35 then
currentY = currentY-1
current=current-4
end
end
elseif key == 203 or key == 30 then –left
if currentX >= 2 then
currentX = currentX -11
current = current-1
end
elseif key == 205 or key == 32 then –right
if currentX <=24 then
currentX = currentX +11
current= current+1
end
end
if current == 1 then
color = "magenta"
rs.setBundledOutput(""..currentside.."", colors.magenta)
elseif current == 2 then
color = "orange"
rs.setBundledOutput(""..currentside.."", colors.orange)
elseif current == 3 then
color="green"
rs.setBundledOutput(""..currentside.."", colors.green)
elseif current == 4 then
color = "red"
rs.setBundledOutput(""..currentside.."", colors.red)
elseif current == 5 then
color = "black"
rs.setBundledOutput(""..currentside.."", colors.black)
elseif current == 6 then
color = "gray"
rs.setBundledOutput(""..currentside.."", colors.gray)
elseif current == 7 then
color = "l-gray"
rs.setBundledOutput(""..currentside.."", colors.lightGray)
elseif current== 8 then
color = "cyan"
rs.setBundledOutput(""..currentside.."", colors.cyan)
elseif current == 9 then
color = "pink"
rs.setBundledOutput(""..currentside.."", colors.pink)
elseif current == 10 then
color = "lime"
rs.setBundledOutput(""..currentside.."", colors.lime)
elseif current== 11 then
color = "purple"
rs.setBundledOutput(""..currentside.."", colors.purple)
elseif current == 12 then
color = "yellow"
rs.setBundledOutput(""..currentside.."", colors.yellow)
elseif current == 13 then
rs.setBundledOutput(""..currentside.."", colors.blue)
color = "blue"
elseif current == 14 then
color = "brown"
rs.setBundledOutput(""..currentside.."", colors.brown)
elseif current == 15 then
color = "l-blue"
rs.setBundledOutput(""..currentside.."", colors.lightBlue)
elseif current == 16 then
color = "white"
rs.setBundledOutput(""..currentside.."", colors.white)
elseif current==17 then
color="side"
side()
whileside=2
elseif current==18 then
color="quit"
quit()
end
end
I'm still learning lua and I like to play around with all the Redpower stuff as well as Computercraft.
So I made a program which lets you easily control all the colors on every side.
It's usefull for uncomplicated Redpower circuit testing and maybe even controlling…
if anyone has suggestions how I can improve the code please let me know! I had some problems coding it and couldn't always find satisfying solutions.
here's the code:
Spoiler
local currentX = 1local currentY = 1
local current=1
color="magenta"
whileside = 1
sideout1= "back"
sideout2= "left"
sideout3= "right"
sideout4= "front"
sideout5= "bottom"
sideout6= "top"
while whileside==1 do
term.clear()
term.setCursorPos(1,1)
print("enter bundled cable output side:")
currentside=read()
if currentside== sideout1 then
whileside=2
elseif currentside== sideout2 then
whileside=2
elseif currentside== sideout3 then
whileside=2
elseif currentside== sideout4 then
whileside=2
elseif currentside== sideout5 then
whileside=2
elseif currentside== sideout6 then
whileside=2
end
end
function drawCursor()
term.setCursorPos(currentX, currentY)
write("["..color.."]")
end
function side()
while whileside==2 do
term.clear()
term.setCursorPos(1,1)
write("current side active: "..currentside)
term.setCursorPos(1,3)
print("which side do you want")
print("to be the new output side?")
currentside = read()
if currentside== sideout1 then
whileside=3
elseif currentside== sideout2 then
whileside=3
elseif currentside== sideout3 then
whileside=3
elseif currentside== sideout4 then
whileside=3
elseif currentside== sideout5 then
whileside=3
elseif currentside== sideout6 then
whileside=3
end
end
end
function quit()
term.clear()
term.setCursorPos(2,1)
print("do you really want to quit?")
local n=1
while true do
term.setCursorPos(2,2)
if n==1 then write(">YES< NO ") else write (" YES >NO<") end
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent() end
if b==203 and n==2 then n=1 end
if b==205 and n==1 then n=2 end
if b==28 then print("") break end
end
if n==1 then os.reboot() end
if n==2 then return false end
end
function writecolors()
term.clear()
term.setCursorPos(2,1)
write("magenta")
term.setCursorPos(13,1)
write("orange")
term.setCursorPos(24,1)
write("green")
term.setCursorPos(35,1)
print("red")
term.setCursorPos(2,2)
write("black")
term.setCursorPos(13,2)
write("gray")
term.setCursorPos(24,2)
write("l-gray")
term.setCursorPos(35,2)
write("cyan")
term.setCursorPos(2,3)
write("pink")
term.setCursorPos(13,3)
write("lime")
term.setCursorPos(24,3)
write("purple")
term.setCursorPos(35,3)
write("yellow")
term.setCursorPos(2,4)
write("blue")
term.setCursorPos(13,4)
write("brown")
term.setCursorPos(24,4)
write("l-blue")
term.setCursorPos(35,4)
write("white")
term.setCursorPos(2,6)
write("side")
term.setCursorPos(13,6)
write("quit")
term.setCursorPos(1,13)
write("side: "..currentside)
end
while true do –/////////while//////////
writecolors()
drawCursor()
local e,key = os.pullEvent( "key" )
if key == 17 or key == 200 then –up
if currentY >= 2 then
currentY = currentY -1
current= current-4
if currentY==5 then
currentY= currentY-1
end
end
elseif key == 31 or key == 208 then –down
if currentY <=5 then
currentY = currentY +1
current = current+4
if currentY == 5 then
currentY = currentY+1
end
if currentY == 4 and currentX== 35 then
currentY = currentY-1
current=current-4
end
end
elseif key == 203 or key == 30 then –left
if currentX >= 2 then
currentX = currentX -11
current = current-1
end
elseif key == 205 or key == 32 then –right
if currentX <=24 then
currentX = currentX +11
current= current+1
end
end
if current == 1 then
color = "magenta"
rs.setBundledOutput(""..currentside.."", colors.magenta)
elseif current == 2 then
color = "orange"
rs.setBundledOutput(""..currentside.."", colors.orange)
elseif current == 3 then
color="green"
rs.setBundledOutput(""..currentside.."", colors.green)
elseif current == 4 then
color = "red"
rs.setBundledOutput(""..currentside.."", colors.red)
elseif current == 5 then
color = "black"
rs.setBundledOutput(""..currentside.."", colors.black)
elseif current == 6 then
color = "gray"
rs.setBundledOutput(""..currentside.."", colors.gray)
elseif current == 7 then
color = "l-gray"
rs.setBundledOutput(""..currentside.."", colors.lightGray)
elseif current== 8 then
color = "cyan"
rs.setBundledOutput(""..currentside.."", colors.cyan)
elseif current == 9 then
color = "pink"
rs.setBundledOutput(""..currentside.."", colors.pink)
elseif current == 10 then
color = "lime"
rs.setBundledOutput(""..currentside.."", colors.lime)
elseif current== 11 then
color = "purple"
rs.setBundledOutput(""..currentside.."", colors.purple)
elseif current == 12 then
color = "yellow"
rs.setBundledOutput(""..currentside.."", colors.yellow)
elseif current == 13 then
rs.setBundledOutput(""..currentside.."", colors.blue)
color = "blue"
elseif current == 14 then
color = "brown"
rs.setBundledOutput(""..currentside.."", colors.brown)
elseif current == 15 then
color = "l-blue"
rs.setBundledOutput(""..currentside.."", colors.lightBlue)
elseif current == 16 then
color = "white"
rs.setBundledOutput(""..currentside.."", colors.white)
elseif current==17 then
color="side"
side()
whileside=2
elseif current==18 then
color="quit"
quit()
end
end