Jump to content




'For' limit must be a number

turtle lua

5 replies to this topic

#1 MrNorth

  • Members
  • 4 posts

Posted 22 January 2017 - 09:19 AM

So, basically I already tried to make a quaryy program, which actually worked, and right now I'm trying to make a farming program. The issue I'm having concerns the first lines of the farming sequence.

--Place turtle in rightmost position 1, 1, 1
--Declare dimensions
tArgs={...}
tVar={x, z}
for i=1, 2 do
tVar[i]=tonumber(tArgs[i])
end

--forward mining
function turtle.advance(dist)
for Tz=1, dist do
turtle.dig()
turtle.forward()
end
end

--make turns
function turtle.uturnLeft()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
end

function turtle.uturnRight()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
end

--real farming
print("harvesting")
for Tx=1, x do --error line
turtle.advance(z-1)
if Tx%2>0 then
turtle.uturnRight()
else
turtle.uturnLeft()
end
end

It tells me "'for' limit must be a number". I checked with type() function, and tVar[i] are actually numbers.
What do I do now? What am i getting wrong?
Thanks everyone

#2 Admicos

  • Members
  • 207 posts
  • LocationTurkey

Posted 22 January 2017 - 09:32 AM

is "x" a number?

#3 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 22 January 2017 - 03:22 PM

in the second line of --real farming you don't define x anywhere so lua uses nil which is not a number

#4 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 22 January 2017 - 03:50 PM

To build a little on what's been said,with a little repeat and some emphasis - you're using x in your real farming for loop but you never define x. You do define tVar[1] and tVar[2]. If those are the values you want to use, then those are the variables you will have to use. Using type on your tVars will not tell you anything about x, you need to use type(x) to see what x is.

#5 Tazkazz

  • Members
  • 4 posts

Posted 22 January 2017 - 06:35 PM

I'd suggest changing
--Place turtle in rightmost position 1, 1, 1
--Declare dimensions
tArgs={...}
tVar={x, z}
for i=1, 2 do
tVar[i]=tonumber(tArgs[i])
end
to
--Place turtle in rightmost position 1, 1, 1
--Declare dimensions
tArgs={...}
x = tonumber(tArgs[1])
z = tonumber(tArgs[2])


#6 MrNorth

  • Members
  • 4 posts

Posted 23 January 2017 - 11:25 PM

I see. Thank you guys, I had already come to Tazkazz solution but it's good to know.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users