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

A weird error for Turtle Programming

Started by aceyo369, 14 August 2014 - 03:47 PM
aceyo369 #1
Posted 14 August 2014 - 05:47 PM
I have got this error, <For input String: "20then"> when making a turtle to automatically receive wireless signal from another turtle to activate its cutting trees function. I have put down a Left() and Right() function because the turtle may varies on the direction it turns, so its just for convenient to put the functions. But my main error is the For Input String: "20then"

This is the code:
	
local w,h = term.getSize()
	
local direction = "left"
	
local bonemeal = "Bonemeal<slot 3>: "..turtle.getItemCount(3)
	
local sapling = "Sapling: "..turtle.getItemCount(2)
	
local wood = "Wood: "..turtle.getItemCount(1)
	
local function Left()  
	
  turtle.turnLeft()
	
end
	
local function Right()  
	
  turtle.turnRight()
	
end
	
local function harvest()
	
  for i = 1, 4 do
	
	turtle.forward()
	
  end
	
  Left()
	
  turtle.select(3)
	
  for i = 1, 8 do
	
	turtle.place()
	
  end
	
  turtle.select(1)
	
  for i = 1, 6 do
	
	turtle.dig()
	
	turtle.digUp()
	
	turtle.up()
	
  end
	
  for i = 1, 6 do
	
	turtle.down()
	
  end
	
  turtle.select(2)
	
  turtle.place()
	
  Left()
	
  for i = 1, 4 do
	
	turtle.forward()
	
  end
	
  for i = 1, 2 do
	
	Left()
	
  end
	
end
	
local function checkBoneMeal()
	
  if turtle.getItemCount(3) < 32 and turtle.getItemCount(3) > 20then
	
	for i = 4, 11 do
	
	  turtle.select(i)
	
	  turtle.transferTo(i - 1, 32)
	
	end
	
  elseif turtle.getItemCount(3) <= 20 then
	
	turtle.up()
	
	Right()
	
	turtle.forward()
	
	for i = 3, 11 do
	
	  turtle.select(i)
	
	  turtle.suck()
	
	end	
	
	Left()
	
	Left()
	
	turtle.forward()
	
	Right()
	
	turtle.down()
	
  end	
	
  turtle.select(1)
	
end
	
local function checkWood()
	
  if turtle.getItemCount(1) > 30 then
	
	Right()
	
	Right()
	
	turtle.select(1)
	
	turtle.drop(64)
	
	turtle.select(12)
	
	turtle.drop(64)
	
	Right()
	
	Right()
	
  end
	
end
	
local function checkSap()
	
  if turtle.getItemCount(2) < 32 then
	
	Right()
	
	turtle.forward()
	
	turtle.suck()
	
	Left()
	
	Left()
	
	turtle.forward()
	
	Right()
	
  end	
	
end
	
local function allProcess()
	
  checkBoneMeal()
	
  checkSap()
	
  harvest()  
	
end
	
local function main()
	
  rednet.open("right")
	
  while true do
	
	local wood = "Wood: "..turtle.getItemCount(1)
	
	local bonemeal = "Bonemeal<slot 3>: "..turtle.getItemCount(3)
	
	local sapling = "Sapling: "..turtle.getItemCount(2)
	
	local fuelLevel = "Fuel Level: "..turtle.getFuelLevel()
	
	term.clear()
	
	term.setCursorPos(1,1)
	
	print(wood)
	
	print(bonemeal)
	
	print(sapling)
	
	print(fuelLevel)
	
	senderID, message = rednet.receive()
	
	if message == "on" then
	
	  allProcess()
	
	end
	
  end
	
end
	
main()
Edited by
Cranium #2
Posted 14 August 2014 - 06:16 PM
I went ahead and fixed a bit of the formatting for your post, so it's easier for those helping to read.

EDIT: also, I don't believe that's the entirety of your error message.
Edited on 14 August 2014 - 04:19 PM
Bomb Bloke #3
Posted 14 August 2014 - 06:48 PM
if turtle.getItemCount(3) < 32 and turtle.getItemCount(3) > 20then

There's a space missing there.
aceyo369 #4
Posted 15 August 2014 - 01:56 AM
It still didn't solve my error which displays: <For input String: "20then">
theoriginalbit #5
Posted 15 August 2014 - 02:07 AM
Then you didn't add the space. The error For input string: "20then" means that while trying to parse the file it has encountered an invalid variable (variables cannot start with numbers).
aceyo369 #6
Posted 15 August 2014 - 02:27 AM
Its weird because my code doesn't have variables that starts with numbers…
Dragon53535 #7
Posted 15 August 2014 - 02:29 AM
This line:

if turtle.getItemCount(3) < 32 and turtle.getItemCount(3) > 20then
should be

if turtle.getItemCount(3) < 32 and turtle.getItemCount(3) > 20 then
aceyo369 #8
Posted 15 August 2014 - 02:38 AM
Thanks, so bad at spotting that despite not realizing a guy from before solve it already. My bad…
Dragon53535 #9
Posted 15 August 2014 - 02:46 AM
It's fine my friend, i hope your program works the way you need it to now.