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

Attempt to call Nil - Melee Turtle

Started by Zukamimozu, 12 October 2014 - 07:19 PM
Zukamimozu #1
Posted 12 October 2014 - 09:19 PM
So I have a melee turtle set up in this mob farm. Anyways I've been trying for the past 20 minutes trying to figure out why this isn't working…

My code right now is set up so it puts the drops into a chest, and that's the part that isn't working…


local count = turtle.getItemCount(1)
while true do
if count >= 2 then
turtle.turnRight()
turtle.drop(2)
turtle.turnLeft()
else
turtle.attack()
sleep(0.5)
end
end

It's attempting to call nil in line 1… It was working earlier then I changed some stuff and don't remember what I had previously.
Lignum #2
Posted 12 October 2014 - 09:24 PM
Could you please post the entire error message, exactly as Lua outputs it (and code, if any)? Because the program you've provided is syntactically correct.
KingofGamesYami #3
Posted 12 October 2014 - 09:27 PM
Two things:
1 - I'm guessing you mistyped turtle.getItemCount on line 1
2 - the count variable is set initially, and never updated.
Saldor010 #4
Posted 12 October 2014 - 09:28 PM
Your code appears to be working for me.. What computercraft version are you using?
Zukamimozu #5
Posted 12 October 2014 - 09:37 PM
The exact error code is: startup:1: attempt to call nil
The Computercraft version is 1.63
Just checked, it's typed correctly.

Just tried

while true do
if turtle.getItemCount(1) >= 2 then
turtle.turnRight()
turtle.drop(2)
turtle.turnLeft()
else
turtle.attack()
sleep(0.5)
end
end
and now it says: startup:2: attempt to call nil

EDIT: Okay, not quite sure what happened but just broke the turtle and placed it back down and it works now?
Thanks for the quick responses anyways :)/>
Edited on 12 October 2014 - 07:37 PM
Saldor010 #6
Posted 12 October 2014 - 09:37 PM
The exact error code is: startup:1: attempt to call nil
The Computercraft version is 1.63
Just checked, it's typed correctly.

Just tried

while true do
if turtle.getItemCount(1) >= 2 then
turtle.turnRight()
turtle.drop(2)
turtle.turnLeft()
else
turtle.attack()
sleep(0.5)
end
end
and now it says: startup:2: attempt to call nil

You are using this on a turtle, right? Not trying to use it on a computer or emulator? Also, are there any other programs on the turtle? Because those may be interfering with the turtle API.
Edited on 12 October 2014 - 07:37 PM