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

Error in rubber farm program

Started by JaydenLoon3y, 19 January 2013 - 06:33 PM
JaydenLoon3y #1
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
theoriginalbit #2
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
JaydenLoon3y #3
Posted 19 January 2013 - 07:39 PM
is the a way i could fix that
never-mind i reread your post
thanks
theoriginalbit #4
Posted 19 January 2013 - 07:42 PM
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…