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

Help with turtle program.

Started by rahph, 27 February 2015 - 10:19 AM
rahph #1
Posted 27 February 2015 - 11:19 AM
Hey, i just wrote turtle program to build bridges, and after entering numbers in first part of program (just after start) i keep getting: bb:21: attempt to compare function with number error. Please how do I fix it! I only know that it is line 21!

fuel = turtle.getFuelLevel()
term.clear()
turtle.select(1)
term.setCursorPos(2, 6)
textutils.slowPrint("Enter how long should the bridge be?")
term.setCursorPos(2, 7)
textutils.slowPrint("DO NOT ENTER LETTERS OR I WILL CRASH")
term.setCursorPos(19, 8)
long = read()
if tonumber(long) > 20 then
  term.clear()
  term.setCursorPos(15, 6)
  textutils.slowPrint("Too long")
  sleep(5)
  term.clear()
  term.setCursorPos(1, 1)
  return
end
should = tonumber(long)*3
is = turtle.getItemCount
if is == should or is > should then
  for i= 1, tonumber(long) do
	if fuel > 1000 then
	  sleep(2)
	  term.clear()
	  term.setCursorPos(1, 1)
	  print("Enugh fuel. Working")
	  term.setCursorPos(1, 2)
	  print(i)
	  turtle.back()
	  turtle.place()
	  turtle.turnLeft()
	  turtle.forward()
	  turtle.turnRight()
	  turtle.place()
	  turtle.turnRight()
	  turtle.forward()
	  turtle.forward()
	  turtle.turnLeft()
	  turtle.place()
	  turtle.turnLeft()
	  turtle.forward()
	  turtle.turnRight()
	  else
		term.clear()
		term.setCursorPos(1, 1)
		term.print("Not enugh fuel")
		break
	  end
	end
  else
	term.clear()
	term.setCursorPos(1, 1)
	textutils.slowPrint("Sorry. Not enugh items in slot 1!")
	sleep(5)
	term.clear()
	term.setCursorPos(1, 1)
	return
end
Pastebin:
http://pastebin.com/Ae3YheHg
Bomb Bloke #2
Posted 27 February 2015 - 11:36 AM
On line 20, you do this:

is = turtle.getItemCount

"is" ends up pointing to the same function as turtle.getItemCount does.

Presumably you meant to do this:

is = turtle.getItemCount()

This runs the function, and sets "is" to the value it returns.
rahph #3
Posted 27 February 2015 - 12:43 PM
oh. it was just variable…