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

startup:16: attempt to call nil. [Solved] solution in the post

Started by totalspelnerd, 03 January 2013 - 11:14 PM
totalspelnerd #1
Posted 04 January 2013 - 12:14 AM
I've just created an API and when I put it into the mods/computercraft/lua… and so on I get this weird message on my turtles: startup:16: attempt to call nil.

Everything is working like it should but I still get this annoying message.


Here is my API code:

function turn(dir)
   if(dir == "right")then
  turtle.turnRight()
   end
   if(dir == "left")then
  turtle.turnLeft()
   end
   if(tonumber(dir)== 2)then
	turtle.turnRight()
	turtle.turnRight()
   end
end
function forward()
if(turtle.detect()==false)then
	while turtle.forward()==false do
   turtle.attack()
	end
else
	while turtle.forward()==false do
   turtle.dig()
	end
end
end
function gotInvSpace()
cont = false
for i=1,16 do
  if turtle.getItemCount(i)==0 then
   cont = true  
  end
end
return cont
end
function drop()
for i=1,16 do
  turtle.select(i)
  turtle.drop()
end
end
function gotFuel()
if(turtle.getFuelLevel()<=0)then
  for x=1,16 do
  turtle.select(x)
   if turtle.refuel(64)==true then
	x = 16
   end
  end
  while(turtle.getFuelLevel()<=0) do
   turtle.refuel(64)
  end
end
end

Never name an API after another one, if the API name already exist it will give this error :P/>
theoriginalbit #2
Posted 04 January 2013 - 01:12 AM
I've just created an API and when I put it into the mods/computercraft/lua… and so on I get this weird message on my turtles: startup:16: attempt to call nil.

This error code indicates to me that it is an issue in the startup file on the turtles. What is the startup file's code? more precisely what is on line 16?
totalspelnerd #3
Posted 04 January 2013 - 01:18 AM
This error code indicates to me that it is an issue in the startup file on the turtles. What is the startup file's code? more precisely what is on line 16?

I haven't messed around with the startup file so it is just the default startup file that comes with the turtleOS.
remiX #4
Posted 04 January 2013 - 01:26 AM
Is the api called startup?

Remove the api from the apis folder and does it still error?
theoriginalbit #5
Posted 04 January 2013 - 01:28 AM
Also are you actually running CC 1.4?
LNETeam #6
Posted 04 January 2013 - 01:30 AM
Have you ever attempted to call this API or is it right when you power up. Also, on default, the normal APIs are always loaded when powered on, the code on 16

turtle.attack()

This will always show up, because you loaded into default apis, it will attempt to load it even onto a normal turtle that isn't a attack turtle. Add this to catch the error at line 16.

assert(turtle.attack() == true , "Error! Not Compatible Turtle...")

Also, try and load it locally onto the turtle, don't put it directly into the /lua … folder. That's trouble unless you have a fail safe. This will also raise problems when you try to use normal computers. Use:

 if not turtle then
    return false
end
At beginning of code!
totalspelnerd #7
Posted 04 January 2013 - 03:33 AM
still doesn't work. This is what I have now (I've changed the drop function a little but nothing that will change the error). Still the same error.


if not turtle then
	return false
end
function turn(dir)
   if(dir == "right")then
  turtle.turnRight()
   end
   if(dir == "left")then
  turtle.turnLeft()
   end
   if(tonumber(dir)== 2)then
	turtle.turnRight()
	turtle.turnRight()
   end
end
function forward()
if(turtle.detect()==false)then
	while turtle.forward()==false do
   assert(turtle.attack() == true , "Error! Not Compatible Turtle...")
	end
else
	while turtle.forward()==false do
   assert(turtle.dig() == true , "Error! Not Compatible Turtle...")
	end
end
end
function gotInvSpace()
cont = false
for i=1,16 do
  if turtle.getItemCount(i)==0 then
   cont = true  
  end
end
return cont
end
function drop(start, stop)
start = start or 1
stop = stop or 16
for i=start,stop do
  turtle.select(i)
  turtle.drop()
end
end
function gotFuel()
if(turtle.getFuelLevel()<=0)then
  for x=1,16 do
  turtle.select(x)
   if turtle.refuel(64)==true then
	x = 16
   end
  end
  while(turtle.getFuelLevel()<=0) do
   turtle.refuel(64)
  end
end
end
ChunLing #8
Posted 04 January 2013 - 05:56 AM
What's this api called?

After you get the error, you can still use your programs, right? Are there any programs you can't use anymore?

What about shell commands like rm and mv? Do those work?
LNETeam #9
Posted 04 January 2013 - 06:10 AM
What is the name of the API?
totalspelnerd #10
Posted 04 January 2013 - 07:36 AM
What's this api called?
okay, I found the problem. My API was called help and that API already existed so it gave me an error all the time. I'm stupid :P/> Thanks for the help! would never figure that out if you guys didn't ask for the name of the API :D/>