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

[Closed][Lua][Error] "testmine:2: attempt to index ? (a function value)

Started by IceCrasher, 25 March 2013 - 01:39 AM
IceCrasher #1
Posted 25 March 2013 - 02:39 AM
Hi guys, I wrote my one litte API (mine: http://pastebin.com/gnyqhulx) and then i puted some more functions in it. Suddenly when I ran my "testmine" programm (http://pastebin.com/Rs5rzRRy) it gave me this error message and didn't work at all:
testmine:2: attempt to index ? (a function value)

Thank you for reading and may supporting :)/>


testmine:
Spoiler
os.loadAPI("mine")
mine.invClear()

mine:
Spoiler

function invClear()
  turtle.select(16)
  while not turtle.placeUp() do
	turtle.digUp()
  end
  for i = 1, 10 do
	turtle.select(i)
	turtle.dropUp()
  end
  turtle.select(16)
  turtle.digUp()
end
function refuel(x)
  if x > turtle.getFuelLevel() then
	invClear()
	turtle.select(15)
	while not turtle.placeUp() do
	  turtle.digUp()
	end
	end
  while x > turtle.getFuelLevel() do
	turtle.suckUp()
	turtle.refuel()
  end
  turtle.select(15)
  turtle.digUp()
end
function mine(x)
  refuel(x + 10)
  for i = 1, x do
	if turtle.getItemCount(8) > 0 then
	  invClear()
	end
	while not turtle.forward() do
	  turtle.dig()
	end
	while turtle.detectUp() do
	  turtle.digUp()
	end
	turtle.digDown()
  end
end

function turn()
  if Richtung == "r" then
	turtle.turnRight()
	mine(1)
	turtle.turnRight()
	Richtung = "l"
  else
	turtle.turnLeft()
	mine(1)
	turtle.turnLeft()
	Richtung = "r"
  end
end
function calcx()
  if (mgox - mendx) >= 0 then
	return mgox - mendx
  else
	return mendx - mgox
  end
end
function calcy()
  if (mgoy - mendy) >= 0 then
	return mgoy - mendy
  else
	return mendy - mgoy
  end
end
function calcz()
  if (mgoz - mendz) >= 0 then
	return mgoz - mendz
  else
	return mendz - mgoz
  end
end
remiX #2
Posted 25 March 2013 - 03:09 AM
Are you maybe not running this on a turtle? :P/>
IceCrasher #3
Posted 25 March 2013 - 03:24 AM
haha, but unfortunately i'm running in on a turtle…
remiX #4
Posted 25 March 2013 - 05:43 AM
Add a print( type( mine ) ) after loading the api and check what it outputs. Should be function