Posted 18 March 2013 - 06:14 AM
This is my first large project code so it is most likely to be sloppy and have many errors and is probably over complicated. The setup
currently consists of 11 different computers, each with a wireless modem. There are 10 floors, each with their own computer which will transmit to one central computer which we keep track of the current floor, move the elevator when it receives a message from one of the computers or receives a redstone input from a wireless retriever through bundled cables. Currently the central elevator code, or Elevator_Main will seem to crash the computer and give the following error message: nil: vm error: java.lang.NullPointerException.
The current version of Computer Craft is 1.3
The code is as follows:
I would like to put in a screenshot of the setup but I don't know to insert an image from my computer. also in the Debug function it should be a regular b but the forums change it.
currently consists of 11 different computers, each with a wireless modem. There are 10 floors, each with their own computer which will transmit to one central computer which we keep track of the current floor, move the elevator when it receives a message from one of the computers or receives a redstone input from a wireless retriever through bundled cables. Currently the central elevator code, or Elevator_Main will seem to crash the computer and give the following error message: nil: vm error: java.lang.NullPointerException.
The current version of Computer Craft is 1.3
The code is as follows:
local modem = peripheral.wrap("top")
rednet.open("top")
a = 0
b = 0
function Floors() --Relates the message send by wireless modems to a number value
while true do
if message == "0" then
b = 0
elseif message == "18" then
b = 18
elseif message == "30" then
b = 30
elseif message == "42" then
b = 42
elseif message == "54" then
b = 54
elseif message == "66" then
b = 66
elseif message == "78" then
b = 78
elseif message == "90" then
b = 90
elseif message == "109" then
b = 109
elseif message == "114" then
b = 114
else
b = b
end
end
end
function movement() --Coressponds to four transmitters which are conected to 2 frame motors, 1 block breaker, and 1 deployer
while true do
while a < b do
redstone.setBundledOutput("right", colors.green) --Places frame
sleep(.2)
redstone.setBundledOutput("right", colors.white) --Moves elevator up
a=a+1
sleep(1)
end
while a > b do
redstone.setBundledOutput("right", colors.red) --Breakes frame
sleep(.2)
redstone.setBundledOutput("right", colors.black) --Moves elevator down
a=a-1
sleep(1)
end
while a == b do
redstone.setBundledOutput("right", 0)
id, message = rednet.receive()
sleep(1)
end
end
end
function buttons() --Buttons on each floor that are hooked up to transmitters to 'call' the elevator to that level
while true do
if rs.getBundledInput("back", colors.pink) == true then
b = 0
elseif rs.getBundledInput("back", colors.black) == true then
b = 18
elseif rs.getBundledInput("back", colors.white) == true then
b = 30
elseif rs.getBundledInput("back", colors.red) == true then
b = 42
elseif rs.getBundledInput("back", colors.green) == true then
b = 54
elseif rs.getBundledInput("back", colors.blue) == true then
b = 66
elseif rs.getBundledInput("back", colors.gray) == true then
b = 78
elseif rs.getBundledInput("back", colors.yellow) == true then
b = 90
elseif rs.getBundledInput("back", colors.orange) == true then
b = 109
elseif rs.getBundledInput("back", colors.brown) == true then
b = 114
else
b = b
end
end
end
function Doors() --Sends redstone signal to transmitters that move pistons
while true do
while a == 0 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.orange)
redstone.setBundledOutput("left", colors.brown)
end
while a == 18 and a == b do
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.orange)
redstone.setBundledOutput("left", colors.brown)
end
while a == 30 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.orange)
redstone.setBundledOutput("left", colors.brown)
end
while a == 42 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.orange)
redstone.setBundledOutput("left", colors.brown)
end
while a == 54 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.orange)
redstone.setBundledOutput("left", colors.brown)
end
while a == 66 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.orange)
redstone.setBundledOutput("left", colors.brown)
end
while a == 78 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.orange)
redstone.setBundledOutput("left", colors.brown)
end
while a == 90 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.orange)
redstone.setBundledOutput("left", colors.brown)
end
while a == 109 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.brown)
end
while a == 114 and a == b do
redstone.setBundledOutput("left", colors.black)
redstone.setBundledOutput("left", colors.white)
redstone.setBundledOutput("left", colors.red)
redstone.setBundledOutput("left", colors.green)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("left", colors.gray)
redstone.setBundledOutput("left", colors.yellow)
redstone.setBundledOutput("left", colors.orange)
end
end
end
function Debug() --Displays the 'a' and 'b' values for debugging purposes only
while true do
term.clear()
term.setCursorPos(1,1)
print("Curently at "..a)
print("Moving to " ..B)/>/>
sleep(.5)
end
end
Floors()
movement()
buttons()
Doors()
Debug()
I would like to put in a screenshot of the setup but I don't know to insert an image from my computer. also in the Debug function it should be a regular b but the forums change it.