Posted 20 December 2012 - 06:43 PM
Trying to write a simple mining program to tunnel down a set distance then move over and come back then dump etc. (my second program ever)
Wrote this function to handle refueling.
I am getting an "attemp to call nil" error on the first "if" statement. (should be coloured red) My problem is that I wrote the bottom "If" statement (coloured blue) for my first program and it works just fine. My question is do i have a problem with the lua syntax or the Turtle (api) or something else entirely.
I've put the whole program below for anyone who would like to look and see. Please keep in mind till a week ago i had no idea lua or computercraft existed. The blue text is my notes to myself while trying to learn this stuff. I've also never got this program to run past the error reprorted above so bugs, random capital letters, and other assorted screwups are still to be found therein.
P.S. If you know how to keep the formatting for text pasted into a post you could tack that on to your answer as well.. :huh:/>
Wrote this function to handle refueling.
function juice()
turtle.select(1)
if turtle.getitemCount(1) < 1 then
print ("Feed Me")
repeat
sleep (5)
until turtle.getitemCount(1) > 10
end
if turtle.getFuelLevel() < 5 then
repeat
print ("Fueling Standby")
turtle.select(1)
turtle.refuel(1)
until turtle.getFuelLevel() > 50
end
end
I am getting an "attemp to call nil" error on the first "if" statement. (should be coloured red) My problem is that I wrote the bottom "If" statement (coloured blue) for my first program and it works just fine. My question is do i have a problem with the lua syntax or the Turtle (api) or something else entirely.
I've put the whole program below for anyone who would like to look and see. Please keep in mind till a week ago i had no idea lua or computercraft existed. The blue text is my notes to myself while trying to learn this stuff. I've also never got this program to run past the error reprorted above so bugs, random capital letters, and other assorted screwups are still to be found therein.
P.S. If you know how to keep the formatting for text pasted into a post you could tack that on to your answer as well.. :huh:/>
Spoiler
--variable thingy I have very little idea how this part works I "borrowed" this bit from somewhere. i'm pretty sure it sets a variable from a number inputed after program command.
turtle.select(1)
local tArgs = { ... }
local togo = tonumber(tArgs[1]) --sets the tArgs variable string to a number usable by the program...I think
togo = togo or 1 -- No idea why this is line here
--fuel function. Pause if out of fuel (put fuel in slot 1)
function juice()
turtle.select(1)
if turtle.getitemCount(1) < 1 then
print ("Feed Me")
repeat
sleep (5)
until turtle.getitemCount(1) > 10
end
if turtle.getFuelLevel() < 5 then
repeat
print ("Fueling Standby")
turtle.select(1)
turtle.refuel(1)
until turtle.getFuelLevel() > 50
end
end
--Tunnel functions
function clearud()
if turtle.detectUp() then
turtle.digUP()
end
if turtle.detectDown() then
turtle.digDown()
end
end
function dig()
juice()
if turtle.detect() then
repeat
turtle.dig()
sleep(0.5)
until turtle.detect() == false
turtle.forward()
clearud()
else
turtle.forward()
clearud()
end
end
--turn arount at far end function
function gohome()
turtle.turnRight()
for i = 1, 3 do
dig()
end
turtle.turnRight()
end
--Dump and turn at end Function
function dumpturn()
print ("Unloading standby...")
local x=1
while x<16 do --unload slots 2-16
x=x+1
turtle.select(x)
turtle.drop()
end
turtle.turnLeft()
for i = 1, 3 do
dig()
end
turtle.turnLeft()
end
---Main program
for i = 1, 10 do
for i = 1, togo do
dig()
end
gohome()
for i = 1, togo do
dig()
end
dumpturn()
end
Edited by