Posted 24 May 2012 - 09:55 PM
I am trying to write a program that moves a mining turtle down to a specific level on the map
–y0 is the current level the turtle is at and target is where its trying to go
print("I am at?")
local y0=read()
print("I am going to?")
local target=read()
print("I am at ",y0," and going to ",target) –To double check that y0 and target are numbers
while y0>target do –The problem is here somewhere
turtle.digDown()
turtle.down()
y0=y0-1
print("I'm now at: ",y0," and going to ",target,"
sleep(1)
end
Using 15 and 10 for example y0 and target values the output is:
I am at 15 and going to 10
**turtle breaks block below it**
**turtle moves down 1 block**
"I'm now at 14 and going to 10
I keep getting the error:
"decend:7: attempt to compare number with string expected, got number"
So that leads me to believe that y0 or target "while y0>target do" is not a number, but when I print them at the end they are numbers and the code runs through the while loop the first time. So I'm stumped (I'm probably missing something kind of simple).
EDIT: Thanks thebros, so I take it the issue was that I had numbers in my variable names?
EDIT2: Nope, looks like I need to read up on "tonumber" , thanks again!
–y0 is the current level the turtle is at and target is where its trying to go
print("I am at?")
local y0=read()
print("I am going to?")
local target=read()
print("I am at ",y0," and going to ",target) –To double check that y0 and target are numbers
while y0>target do –The problem is here somewhere
turtle.digDown()
turtle.down()
y0=y0-1
print("I'm now at: ",y0," and going to ",target,"
sleep(1)
end
Using 15 and 10 for example y0 and target values the output is:
I am at 15 and going to 10
**turtle breaks block below it**
**turtle moves down 1 block**
"I'm now at 14 and going to 10
I keep getting the error:
"decend:7: attempt to compare number with string expected, got number"
So that leads me to believe that y0 or target "while y0>target do" is not a number, but when I print them at the end they are numbers and the code runs through the while loop the first time. So I'm stumped (I'm probably missing something kind of simple).
EDIT: Thanks thebros, so I take it the issue was that I had numbers in my variable names?
EDIT2: Nope, looks like I need to read up on "tonumber" , thanks again!