Jump to content




Error in rubber farm program


  • You cannot reply to this topic
3 replies to this topic

#1 JaydenLoon3y

  • Members
  • 19 posts

Posted 19 January 2013 - 07:33 PM

ok so i have made a rubber farm program using the treetap turtle from misc peripherals mod(all it does is change turtle.dig to harvest rubber instead)

and i get this error

RubberFarm:56:Attempt to compare string with number expected, got string

I know what it means but i am not sure how to fix it

here is the code

term.clear()
term.setCursorPos(1,1)
write("Distance Between Trees: ")
local space = read()
term.setCursorPos(1,2)
write("Number Of Rows: ")
local rows = read()
term.setCursorPos(1,3)

local function tap()
  turtle.dig()
end

local function up()
  while turtle.detect() == true do
    turtle.select(2)
    tap()
    turtle.up()
  end
end

local function down()
  while turtle.detectDown() == false do
    turtle.down()
  end
end

local function tree()
  for t=1,4 do
    up()
    down()
    turtle.turnRight()
    turtle.forward()
    turtle.turnLeft()
    turtle.forward()
    turtle.turnLeft()
  end
end

local function turnaround()
  turtle.turnRight()
  turtle.turnRight()
end

local function row()
  for t=1,2 do
	tree()
  for s=1,space do
	turtle.back()
   end
  turnaround()
   end
end

while rows > 0 do
  if rows ~= 0 then
    row()
    rows = rows - 1
  if rows ~= 1 then
    turtle.turnRight()
    for rs=1,space do
    turtle.forward()
  end
    turtle.turnLeft()
  end
end
end


#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 19 January 2013 - 07:35 PM

The problem is this
local rows = read()
It should be this
local rows = tonumber( read() )
it because the input is read as a string...
later you do
while rows > 0 do
a string cannot be compared to a number

#3 JaydenLoon3y

  • Members
  • 19 posts

Posted 19 January 2013 - 07:39 PM

is the a way i could fix that
never-mind i reread your post
thanks

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 19 January 2013 - 07:42 PM

View PostJaydenLoon3y, on 19 January 2013 - 07:39 PM, said:

is the a way i could fix that
never-mind i reread your post
thanks
haha I just reread my post and was like o.O ... i never actually put the problem in just the solution... oops... lol...





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users