Posted 14 October 2012 - 03:25 AM
In the following file, i can't reference any table value. says: Attemp to index a nil value ? at line 52. Help would be really appreciated.
function reFuel()
if turtle.getFuelLevel()<50 then
print("Refueling...")
turtle.turnRight()
turtle.turnRight()
turtle.select(1)
turtle.suck()
turtle.drop(turtle.getItemCount()-2)
turtle.refuel(2)
turtle.turnLeft()
turtle.turnLeft()
turtle.select(1)
end
end
function moveToChest(:)/>/>
for i=1,b do
turtle.forward()
end
turtle.turnRight()
end
function goBackHome(:)/>/>
turtle.turnLeft()
for j=1,b do
turtle.back()
end
turtle.turnRight()
turtle.drop()
turtle.turnLeft()
end
function readName()
rednet.open("right")
while true do
turtle.select(1)
shell.run("clear")
print("Waiting for Server Instructions")
id,message = rednet.receive()
print(message)
if message == recipe[name] then
rednet.send(id,"Getting Required Items")
craftRecipe(recipe[name])
rednet.send(id,"Crafting Complete")
else
rednet.send(id,"I Don't Know That Recipe")
sleep(2)
end
end
end
function craftRecipe(recipe)
moveToChest(recipe.chest) [b][size=5] -- HERE IS THE ERROR LINE[/size][/b]
turtle.select(1)
for k,v in pairs(recipe.map) do
turtle.select(k)
if v then
turtle.suck()
turtle.drop(turtle.getItemCount(k)-1)
end
end
turtle.craft()
goBackHome(recipe.chest)
end
-- End of Basic Functions
-- My crafting system is based on tables
recipe={
["stick"] = {
count=2, [b][size=5]-- THESE ARE THE REFERENCED TABLES[/size][/b]
chest=3,
map={
[1]=false, [2]=false, [3]=false,
[5]=false, [6]=true, [7]=false,
[9]=false, [10]=true, [11]=false
}
},
["furnace"] = {
count=8,
chest=4,
map={
[1]=true, [2]=true, [3]=true,
[5]=true, [6]=false, [7]=true,
[9]=true, [10]=true, [11]=true
}
}
}
-- End of Recipes List
reFuel()
readName()