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

[Help]-[Lua]-[turtle]-[Problem] What's with my "=" ?

Started by harlekintiger, 16 December 2012 - 06:08 AM
harlekintiger #1
Posted 16 December 2012 - 07:08 AM
Hello,
I wrote a programm for a turtle to chop down a redwood tree. The problem is: It has an error if it reach a line with a "="…
It say something like that:"XXXXXXX :4: "=" probably". It did it by the line "x=x+0" by the line "x=x+1" and also the line "for i=1,x do " didn't work…

I tried to rewrite it without "=", but the result was that:

turtle.dig()
turtle.forward()
turtle.dig()
while turtle.detectUp() do
turtle.digUp()
turtle.Up()
turtle.dig()
x = x+1
end
turtle.turnRight()
turtle.dig()
turtle.forward
turtle.turnLeft()
turtle.dig()
while i < x do
i = i+1
turtle.digDown()
turtle.down()
turtle.dig()
end

It chops 2blocks at the bottom and then print the message:
"chop:4: attemps to perform arithmetic
__add on nill and number"
It have no idea what that could mean….

If you wish, I can set the code to the first one and write the error-message with the "=" here exactly.

I hope someone can help me, please qick - I need the charcoal for my quarry ;D
(I don't understand how to craft solar panels…)

Thank you at least for reading since here! ;D
Ulthean #2
Posted 16 December 2012 - 07:10 AM
You never initialised your x and your y, add:

x = 0
y = 0

at the start of the program
harlekintiger #3
Posted 16 December 2012 - 11:02 AM
You never initialised your x and your y, add: x = 0 y = 0 at the start of the program
You scares me man! Why do you know I used "y"?! I just wrote about "x" and "i" !

But I tested it and: It works! Thanks buddy ;D
I feel shame… that was a stupid mistake.

Thanks again, that realy helped me out a lot!! (Already have stacks of charcoal ;D )
(And sorry, I just recognize that I just havn't answerd… that awesome is my turtle!)
theoriginalbit #4
Posted 16 December 2012 - 01:31 PM

for i = 1, x do

should work fine, when x is a number and higher than 1 :)/>