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

Help please! I suspect a ton of problems.

Started by TheScorpionSamurai, 15 July 2012 - 09:03 PM
TheScorpionSamurai #1
Posted 15 July 2012 - 11:03 PM
this is my code for a mining turtle. Can you help me find what's wrong? the error i got was"lua:1:attempt to index ? (a nil value)"


function dig( _input1, _input2, _input3 )
x ::= _input1
y ::= _input2
z ::= _input3
a ::= 0
b ::= 0
c ::= 0
turtle.digDown()
while c < z-1 do –if not at depth z, empty the layer
while b < y-1 do –if not at width y, empty the row
while a < x-1 do – if not a length x, empty the block ahead
if turtle.detect() == false then
turtle.forward()
a = a+1
else
turtle.dig()
turtle.forward()
a = a+1
end
end
if b=0 then –if the first row was just dug, make a left u-turn
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft
b = b+1
else –if the second row was just dug, make a right u-turn
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
b = b+1
end
a=0
end
turtle.turnRight()
for i=1, y-1 do
turtle.forward()
end
turtle.turnRight()
for i=1, x-1 do
turtle.forward()
end
for i=1, 2 do
turtle.turnRight()
end
turtle.digDown()
end
for i=1, z do – get out
turtle.up()
end
end
Pinkishu #2
Posted 15 July 2012 - 11:31 PM
Problem #1: wrong section
MysticT #3
Posted 15 July 2012 - 11:39 PM
Problem #2: Wrong syntax.
In lua the assignment operator is =, not ::=
candycool1234 #4
Posted 21 September 2012 - 02:45 AM
well for starters your basic move and dig are turtle.place() , turtle.dig() , turtle.forward() , turtle.turnLeft() , turtle.turnRight()
so you have it wrong start to stop.
PixelToast #5
Posted 21 September 2012 - 02:47 AM
the wiki and help command are your friends
Fatal_Exception #6
Posted 21 September 2012 - 04:05 AM
I can see how someone might be confused about the lua assignment syntax from reading the lua manual.

The section on variables does state:
A single name can denote a global variable or a local variable (or a function's formal parameter, which is a particular kind of local variable):

var ::= Name
Many readers might expect this to be a verbatim example of how to declare a variable in lua, not the formal BNF specification, which means absolutely nothing to anyone not from a computer science background. Even then, it's still a detail easily overlooked, especially considering its similarity to the Pascal assignment operator, ":="