Posted 24 March 2013 - 04:02 PM
I'm trying to make my first API. Right now it just has a few functions for how I like to do my turtle quarrys and I'm trying to get it to work. I know that all of my functions are working and I know that I have the right name for the function but when I try to load the API onto a different program and attempt to use a function, it gives me the error:
If someone could tell me what I am doing wrong that would be greatly appreciated!
Thanks! :D/>
quarry13: attempt to call nill
API Code:
local function numbItemsInInv()
local items = 0
for i = 1, 16 do
items = items + turtle.getItemCount(i)
end
return items
end
local function forward(forw)
if tonumber(forw) == nil then
forw = 1
end
for i = 1,forw do
while not turtle.forward() do
turtle.dig()
turtle.attack()
end
end
end
local function up(up)
if tonumber(up) == nil then
up = 1
end
for i = 1,tonumber(up) do
while not turtle.up() do
turtle.digUp()
turtle.attackUp()
end
end
end
local function empty()
turtle.select(16)
up()
turtle.down()
turtle.placeUp()
items = numbItemsInInv()
while items ~= 0 do
print("Try to empty the turtle's inventory")
for i = 1,16 do
turtle.select(i)
turtle.dropUp()
end
items = numbItemsInInv()
if items ~= 0 then
print("Failed to empty inventory")
sleep(5)
end
end
print("Inventory is empty!")
sleep(8)
turtle.select(1)
turtle.digUp()
turtle.transferTo(16)
end
local function inv()
if turtle.getItemCount(15) > 0 then
empty()
end
return
end
local function refuel()
fuel = turtle.getFuelLevel()
while fuel < 300 do
print("I don't have enough fuel!")
turtle.refuel()
sleep(2)
end
print("I got enough fuel!")
end
local function columnd(depth)
refuel()
for i = 1,tonumber(depth) do
turtle.digDown()
turtle.down()
for i = 1,4 do
turtle.dig()
turtle.turnLeft()
end
inv()
end
end
local function columna(depth)
refuel()
for i = 1,tonumber(depth) do
for i = 1,4 do
turtle.dig()
turtle.turnLeft()
end
inv()
turtle.digUp()
turtle.up()
end
end
local function clean(depth)
for i = 1,tonumber(depth) do
turtle.digDown()
turtle.down()
turtle.dig()
inv()
end
turtle.turnRight()
forward(1)
turtle.turnLeft()
for i = 1,tonumber(depth) do
turtle.dig()
up(1)
inv()
end
empty()
end
local function four(four)
columnd(four)
empty()
forward(3)
columna(four)
empty()
turtle.turnLeft()
forward(3)
turtle.turnRight()
columnd(four)
empty()
turtle.turnLeft()
turtle.turnLeft()
forward(3)
turtle.turnRight()
turtle.turnRight()
columna(four)
empty()
forward(1)
turtle.turnRight()
forward(1)
turtle.turnLeft()
clean(four)
print("I'm done!")
end
Program where I try to use the API:
os.loadAPI("qry")
local tArgs = {...}
if ... == "clean" then
qry.clean() --The error also occurs on this line, so I'm pretty sure it is not a problem with the API
elseif ... == nil then
print("Am I in the bottom right hand corner?")
print("Y/N")
event, key = os.pullEvent("key")
if key == 21 then
print("How far down?")
local four = read() --The variable 'four' is used in the function to determine how far down it should go
print("Starting!")
qry.four(four) --Where the error occurs
elseif key == 49 then
print("Well put me there!")
sleep(2)
os.reboot()
end
end
I've looked up tutorials on how to use and load API's and I thought I was doing everything right.If someone could tell me what I am doing wrong that would be greatly appreciated!
Thanks! :D/>