Posted 16 February 2013 - 06:32 PM
EDIT: Solved problem, the function needed to be something else other than "craft".
I'm attempting to create a code for crafting tools in a crafty turtle. There is a function called "craft" in the code, when attempting to use it however, I get the error saying its not a function, but actually a string. edit: Actual error is "craft:(line the craft function was called during the program running): attempt to call string". So for crafting a sword it comes up with "craft:43: attempt to call string" and when crafting a pickaxe it comes up with "craft:53: attempt to call string".
craft
[indent=1]for slot = 1, 14, 1 do[/indent]
[indent=2]turtle.select(slot)[/indent]
[indent=2]if turtle.compareTo(15) == true then[/indent]
[indent=3]turtle.transferTo(15, turtle.getItemCount(slot))[/indent]
[indent=2]elseif turtle.compareTo(16) == true then[/indent]
[indent=3]turtle.transferTo(16, turtle.getItemCount(slot))[/indent]
[indent=2]elseif turtle.compareTo(14) == true then[/indent]
[indent=2]else[/indent]
[indent=3]print("Improper item in turtle inventory.")[/indent]
[indent=2]end[/indent]
[indent=1]end[/indent]
end
function dump()
[indent=1]turtle.select(15)[/indent]
[indent=1]turtle.dropDown(turtle.getItemCount(15))[/indent]
[indent=1]turtle.select(16)[/indent]
[indent=1]turtle.dropDown(turtle.getItemCount(16)[/indent]
end
function craft()
[indent=1]dump()[/indent]
[indent=1]turtle.craft(1)[/indent]
[indent=1]print("Please collect crafted item")[/indent]
end
function handle()
[indent=1]for slot = 6, 10, 4 do[/indent]
[indent=1]turtle.select(16)[/indent]
[indent=1]turtle.transferTo(slot, 1)[/indent]
end
end
function sword()
[indent=1]cleararea()[/indent]
[indent=1]for slot = 2, 6, 4 do[/indent]
[indent=2]turtle.select(15)[/indent]
[indent=2]turtle.transferTo(slot, 1)[/indent]
[indent=1]end[/indent]
[indent=1]turtle.select(16)[/indent]
[indent=1]turtle.transferTo(10, 1)[/indent]
[indent=1]craft()[/indent]
end
function pickaxe()
[indent=1]cleararea()[/indent]
[indent=1]for slot = 1, 3, 1 do[/indent]
[indent=2]turtle.select(15)[/indent]
[indent=2]turtle.transferTo(slot, 1)[/indent]
[indent=1]end[/indent]
[indent=1]handle()[/indent]
[indent=1]craft()[/indent]
end
print("Please insert sticks into slot 16.")
print("Please insert material into slot 15.")
print("Pleae remove any items in slot 14.")
print("What would you like to craft?")
craft = io.read()
if craft == "sword" then
[indent=1]sword()[/indent]
elseif craft == "pickaxe" then
[indent=1]pickaxe()[/indent]
else
[indent=1]print("I do not know how to craft that.")[/indent]
end
I've also run a test where it just calls the craft function and it came up with the same error with the line again being the line where the function was called.
part of code edited
print("Please insert material into slot 15.")
print("Pleae remove any items in slot 14.")
print("What would you like to craft?")
craft = io.read()
if craft == "sword" then
[indent=1]sword()[/indent]
elseif craft == "pickaxe" then
[indent=1]pickaxe()[/indent]
elseif craft == "craft" then
[indent=1]craft()[/indent]
else
[indent=1]print("I do not know how to craft that.")[/indent]
end
I'm attempting to create a code for crafting tools in a crafty turtle. There is a function called "craft" in the code, when attempting to use it however, I get the error saying its not a function, but actually a string. edit: Actual error is "craft:(line the craft function was called during the program running): attempt to call string". So for crafting a sword it comes up with "craft:43: attempt to call string" and when crafting a pickaxe it comes up with "craft:53: attempt to call string".
craft
Spoiler
function cleararea()[indent=1]for slot = 1, 14, 1 do[/indent]
[indent=2]turtle.select(slot)[/indent]
[indent=2]if turtle.compareTo(15) == true then[/indent]
[indent=3]turtle.transferTo(15, turtle.getItemCount(slot))[/indent]
[indent=2]elseif turtle.compareTo(16) == true then[/indent]
[indent=3]turtle.transferTo(16, turtle.getItemCount(slot))[/indent]
[indent=2]elseif turtle.compareTo(14) == true then[/indent]
[indent=2]else[/indent]
[indent=3]print("Improper item in turtle inventory.")[/indent]
[indent=2]end[/indent]
[indent=1]end[/indent]
end
function dump()
[indent=1]turtle.select(15)[/indent]
[indent=1]turtle.dropDown(turtle.getItemCount(15))[/indent]
[indent=1]turtle.select(16)[/indent]
[indent=1]turtle.dropDown(turtle.getItemCount(16)[/indent]
end
function craft()
[indent=1]dump()[/indent]
[indent=1]turtle.craft(1)[/indent]
[indent=1]print("Please collect crafted item")[/indent]
end
function handle()
[indent=1]for slot = 6, 10, 4 do[/indent]
[indent=1]turtle.select(16)[/indent]
[indent=1]turtle.transferTo(slot, 1)[/indent]
end
end
function sword()
[indent=1]cleararea()[/indent]
[indent=1]for slot = 2, 6, 4 do[/indent]
[indent=2]turtle.select(15)[/indent]
[indent=2]turtle.transferTo(slot, 1)[/indent]
[indent=1]end[/indent]
[indent=1]turtle.select(16)[/indent]
[indent=1]turtle.transferTo(10, 1)[/indent]
[indent=1]craft()[/indent]
end
function pickaxe()
[indent=1]cleararea()[/indent]
[indent=1]for slot = 1, 3, 1 do[/indent]
[indent=2]turtle.select(15)[/indent]
[indent=2]turtle.transferTo(slot, 1)[/indent]
[indent=1]end[/indent]
[indent=1]handle()[/indent]
[indent=1]craft()[/indent]
end
print("Please insert sticks into slot 16.")
print("Please insert material into slot 15.")
print("Pleae remove any items in slot 14.")
print("What would you like to craft?")
craft = io.read()
if craft == "sword" then
[indent=1]sword()[/indent]
elseif craft == "pickaxe" then
[indent=1]pickaxe()[/indent]
else
[indent=1]print("I do not know how to craft that.")[/indent]
end
I've also run a test where it just calls the craft function and it came up with the same error with the line again being the line where the function was called.
part of code edited
Spoiler
print("Please insert sticks into slot 16.")print("Please insert material into slot 15.")
print("Pleae remove any items in slot 14.")
print("What would you like to craft?")
craft = io.read()
if craft == "sword" then
[indent=1]sword()[/indent]
elseif craft == "pickaxe" then
[indent=1]pickaxe()[/indent]
elseif craft == "craft" then
[indent=1]craft()[/indent]
else
[indent=1]print("I do not know how to craft that.")[/indent]
end