This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Revolution's profile picture

Elevator Program

Started by Revolution, 14 April 2013 - 09:25 AM
Revolution #1
Posted 14 April 2013 - 11:25 AM
Okay so me and my friend have been trying to make a program to determine which floor the frame elevator is at and how long it needs to go up to arrive at the players floor

using bundled wire i assigned colors to the floor and the buttons to make it work and converted redstone pipe into signals using wireless redstone to pick up the floor number

while true do
os.pullEvent()
redstone.setBundledOutput("bottom", 0)
term.clear()
term.setCursorPos(1,1)
print("------------------------------------------------------")
term.setCursorPos(14,2)
print("Elevator Receiver")
term.setCursorPos(1,3)
print("--------------------------------------------------------")
print("")
  sleep(3)
if rs.testBundledInput("right", colors.lime) and rs.testBundledInput("left", colors.white) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(23)
  redstone.setBundledOutput("back", 0)
  sleep(3)
elseif rs.testBundledInput("right", colors.pink) and rs.testBundledInput("left", color.white) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(18)
  redstone.setBundledOutput("back", 0)
  sleep(3)
elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", color.white) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(14)
  redstone.setBundledOutput("back", 0)
  sleep(3)

elseif rs.testBundledInput("right", colors.cyan) and rs.testBundledInput("left", color.white) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(10)
  redstone.setBundledOutput("back", 0)
  sleep(3)
//2nd floor up
elseif rs.testBundledInput("right", colors.lime) and rs.testBundledInput("left", colors.orange) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(14)
  redstone.setBundledOutput("back", 0)
  sleep(3)
elseif rs.testBundledInput("right", colors.pink) and rs.testBundledInput("left", color.orange) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(9)
  redstone.setBundledOutput("back", 0)
  sleep(3)
elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", color.orange) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(14)
  redstone.setBundledOutput("back", 0)
//3rd floor up
elseif rs.testBundledInput("right", colors.pink) and rs.testBundledInput("left", color.orange) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(9)
  redstone.setBundledOutput("back", 0)
  sleep(3)
elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", color.orange) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(14)
  redstone.setBundledOutput("back", 0)
//1st floor down
elseif rs.testBundledInput("right", colors.lime) and rs.testBundledInput("left", color.white) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", colors.cyan) and rs.testBundledInput("left", color.white) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", color.white) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", colors.pink) and rs.testBundledInput("left", color.white) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
//2nd floor down
elseif rs.testBundledInput("right", colors.pink) and rs.testBundledInput("left", color.orange) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", color.orange) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", colors.lime) and rs.testBundledInput("left", color.orange) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
//3nd floor down
elseif rs.testBundledInput("right", colors.lime) and rs.testBundledInput("left", color.magenta) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
  sleep(3)
end
end



However we get random errors on line 35 about a nill value or something tho its all the same and shouldnt be happening please help im not sure how to get this working correctly
danny_delmax1 #2
Posted 14 April 2013 - 12:50 PM
After looking at the code, it looks like its all right- except for the commenting


//Words

would be nil- it has no value as a variable, and isn't a comment
(Ignore the forums software, that language isn't lua)


-- print("This will never print")

will never print, because – makes the program ignore the lines, not //

Also, for future reference, ask this in "ask a pro"
I'm requesting it to be moved now
Revolution #3
Posted 14 April 2013 - 02:32 PM
Okay thanks i mannaged to get the program to work correctly with multiple floors ill post the code because it might be useful to someone

while true do
os.pullEvent()
redstone.setBundledOutput("bottom", 0)
term.clear()
term.setCursorPos(1,1)
print("------------------------------------------------------")
term.setCursorPos(14,2)
print("Elevator Receiver")
term.setCursorPos(1,3)
print("--------------------------------------------------------")
print("")
  sleep(3)
if rs.testBundledInput("right", colors.lime) and rs.testBundledInput("left", 1) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(23)
  redstone.setBundledOutput("back", 0)
  sleep(3)
elseif rs.testBundledInput("right", colors.pink) and rs.testBundledInput("left", 1) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(18)
  redstone.setBundledOutput("back", 0)
  sleep(3)
elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", 1) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(14)
  redstone.setBundledOutput("back", 0)
  sleep(3)

elseif rs.testBundledInput("right", colors.cyan) and rs.testBundledInput("left", 1) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(10)
  redstone.setBundledOutput("back", 0)
  sleep(3)

elseif rs.testBundledInput("right", colors.lime) and rs.testBundledInput("left", 2) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(14)
  redstone.setBundledOutput("back", 0)
  sleep(3)
elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", 2) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(6)
  redstone.setBundledOutput("back", 0)

elseif rs.testBundledInput("right", 64) and rs.testBundledInput("left", 2) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(9)
  redstone.setBundledOutput("back", 0)

elseif rs.testBundledInput("right", 64) and rs.testBundledInput("left", 64) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(4)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", 32) and rs.testBundledInput("left", 64) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(9)
  redstone.setBundledOutput("back", 0)


elseif rs.testBundledInput("right", colors.lime) and rs.testBundledInput("left", 8) then
  sleep(4)
  redstone.setBundledOutput("back", colors.white)
  sleep(5)
  redstone.setBundledOutput("back", 0)

elseif rs.testBundledInput("right", colors.purple) and rs.testBundledInput("left", 2) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", colors.purple) and rs.testBundledInput("left", colors.pink) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(14)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", colors.purple) and rs.testBundledInput("left", 8) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(18)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", colors.purple) and rs.testBundledInput("left", 256) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(23)
  redstone.setBundledOutput("back", 0)


elseif rs.testBundledInput("right", colors.cyan) and rs.testBundledInput("left", colors.pink) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(5)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", colors.cyan) and rs.testBundledInput("left", 8) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
elseif rs.testBundledInput("right", colors.cyan) and rs.testBundledInput("left", 256) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(14)
  redstone.setBundledOutput("back", 0)

elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", 8) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(4)
  redstone.setBundledOutput("back", 0)

elseif rs.testBundledInput("right", 128) and rs.testBundledInput("left", 256) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(9)
  redstone.setBundledOutput("back", 0)
  

elseif rs.testBundledInput("right", 64) and rs.testBundledInput("left", 256) then
  sleep(4)
  redstone.setBundledOutput("back", colors.orange)
  sleep(5)
  redstone.setBundledOutput("back", 0)
  sleep(3)
end
end


If your reading this and want to use this remember you need wireless redstone to transmitt the signal and red power for the redstone pipe as that is how the computer knows what level the elevator is at! Thanks!
Lyqyd #4
Posted 14 April 2013 - 05:44 PM
Moved to Ask a Pro.