Posted 19 February 2014 - 05:07 PM
I have made a program that just moves a turtle back and forward between two coordinates when activated from a wireless computer.
I receive error: roof.lua:24: attempt to index ? (a nil value)
code below:
Why does it fail with a simple command of turtle.forward() it worked when I was doing it with a single turtle but when I used two it didnt. However it successfully ran the opening for loop. just wouldnt run the closing part.
Any help appreciated. Thanks
I receive error: roof.lua:24: attempt to index ? (a nil value)
code below:
local locID = tonumber(os.getComputerLabel())
local oPos = vector.new(locID-14,63,182)
local cPos = vector.new(locID-14,63,215)
rednet.open("right")
repeat
local event,p1,p2,p3 = os.pullEvent()
if event=="rednet_message" and p1==13 and p2=="activate" then rednet.send(13,"Activating")
local curPos = vector.new(gps.locate())
local compO = curPos - cPos
local compC = curPos - oPos
if compC.x == 0 and compC.y == 0 and compC.z ==0 then
rednet.send(13,"Turtle "..os.getComputerLabel().."opening")
for x = 0,32,1 do
turtle.back()
turtle.place(1)
end
elseif compO.x == 0 and compO.y == 0 and compO.z ==0 then
rednet.send(13,"Turtle "..os.getComputerLabel().."closing")
for x = 0,32,1 do
turtle.dig()
turle.forward()
end
else
print("Something went wrong here")
end
elseif p2=="stop" then
print("Stop command received from "..p1)
rednet.send(13,"Turtle "..os.getComputerLabel().."stopping")
os.queueEvent("char","x")
else
rednet.send(13,"Command not understood please try again")
end
until event=="char" and p1=="x"
rednet.close("right")
Why does it fail with a simple command of turtle.forward() it worked when I was doing it with a single turtle but when I used two it didnt. However it successfully ran the opening for loop. just wouldnt run the closing part.
Any help appreciated. Thanks