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

[Lua][Error] Bios:338 error?

Started by Robin1225, 12 January 2013 - 02:41 PM
Robin1225 #1
Posted 12 January 2013 - 03:41 PM
Hello!
I am fairly new to Lua, so excuse my noobiness :)/>
This is my first program for harvesting wood from a prebuilt farm…. It obviously needs optimizing but the main problem is
that I am receiving an error when attempting to run the code. I have no clue what I'm doing wrong. I will appreciate any criticism.

The purpose of the super large checkTree() function is because of a custom route planned for the turtle.


Spoiler

local function harvestTree()
	local count=0
	if turtle.detect()==true then
		turtle.dig()
		turtle.forward()
		turtle.digDown()
		turtle.select(2)
		turtle.placeDown()
		turtle.select(1)
		while turtle.detect() do
		  count=count+1
		  turtle.digUp()
		  turtle.up()
		end
		turtle.down(count)
	else
		print("No tree... Continuing")
		turtle.forward()
	end
end
		
local function checkTree()
	turtle.up(6)
	turtle.forward(4)
	turtle.turnLeft()
	turtle.forward()
	harvestTree()
	turtle.forward(2)
	harvestTree()
	turtle.turnRight()
	turtle.forward(2)
	harvestTree()
	turtle.turnRight()
	turtle.forward(2)
	harvestTree()
	turtle.turnLeft()
	turtle.forward(2)
	harvestTree()
	turtle.turnLeft()
	turtle.forward(2)
	harvestTree()
	turtle.turnRight()
	turtle.forward(2)
	harvestTree()
	turtle.turnRight()
	turtle.forward(2)
	harvestTree()
	turtle.foward(3)
	harvestTree()
	turtle.forward(2)
	harvestTree()
	turtle.turnRight()
	turtle.forward(2)
	harvestTree()
	turtle.turnRight()
	turtle.forward(2)
	harvestTree()
	turtle.turnLeft()
	turtle.forward(2)
	harvestTree()
	turtle.turnLeft()
	turtle.forward(2)
	harvestTree()
	turtle.turnRight()
	turtle.forward(2)
	harvestTree()
	turtle.turnRight()
	turtle.forward(2)
	harvestTree()
	turtle.forward(2)
	turtle.turnLeft()
	turtle.forward(4)
	turtle.down(6)
end
	
local function cycleCharcoal
	turtle.select(16)
	turtle.drop()
	turtle.suckUp()
	turtle.drop()
	turtle.suck()
	turtle.dropUp()
	turtle.select(1)
	end
	
local function takeCharcoal()
	turtle.select(16)
	turtle.suck()
		if turtle.getFuelLevel()< 100 then
			turtle.refuel(2)
		else
			print("No fuel needed")
		end
	turtle.select(1)
end
	
local function fillFurnace()
	turtle.select(3)
	for i=4, 16 do
		if turtle.compareTo(i)==true
			turtle.select(i)
			turtle.dropDown()
			turtle.select(3)
		else
			print("Not same")
		end
	end
	turtle.select(1)
end
		
local checkSaplings()
	turtle.select(2)
	turtle.suck()
	for i=3, 16 do
		if turtle.compareTo(i)==true
			turtle.select(i)
			turtle.drop()
			turtle.select(2)
		else
			print("Not same Saps")
		end
	end
	turtle.select(1)
end
	
local checkLogs()
	turtle.select(3)
	if turtle.getItemCout<3 then
		turtle.suckUp()
	else
		print("Enough logs")
	end
	for i=4, 16 do
		if turtle.compareTo(i)==true
			turtle.select(i)
			turtle.dropUp()
			turtle.select(3)
		else
			print("Not Logs")
		end
	end
	turtle.select(1)
end
	
local function furnaceCycle()
	turtle.forward()
	cycleCharcoal()
	turtle.back()
	turtle.up()
	takeCharcoal()
	turtle.up()
	turtle.forward()
	fillFurnace()
	checkSaplings()
	checkLogs()
	turtle.back()
	turtle.down(2)
	turtle.turnRight()
	turtle.turnRight()
end

--Main loop
	local checkTime=10
	local suckCount=0
	local suckTimer --=os.startTimer(1)
	local harvestTimer=os.startTimer(0)
	while true do
	
	  local e,p1,p2=os.pullEvent()
	  if e=="timer" and p1==harvestTimer then
		checkTrees()
		furnaceCycle()
		suckTimer=os.startTimer(1)
		suckCount=0
	  elseif e=="timer" and p1==suckTimer then
		turtle.suck()
		suckCount=suckCount+1
		if suckCount<60 then
		  suckTimer=os.startTimer(10)
		else
		  harvestTimer=os.startTimer(1)
		end
	  end	
	end
theoriginalbit #2
Posted 12 January 2013 - 03:44 PM
What is the error message… it will help narrow down where the problem is…

EDIT: Found it maybe… or maybe found one…. in checkLogs()


if turtle.compareTo(i)==true

should be

if turtle.compareTo( i ) then

you missed the then

same issue in checkSaplings() and fillFurnace()
Edited on 12 January 2013 - 02:47 PM
Robin1225 #3
Posted 12 January 2013 - 03:46 PM
I uploaded to pastebin and downloaded via the http api and named the program logger.

Error message is the following
bios:338: [string "logger"]:77: '(' expected
theoriginalbit #4
Posted 12 January 2013 - 03:48 PM
Edited reply with some errors…

also as for the error message the function cycleCharcoal is missing the () at the end…
theoriginalbit #5
Posted 12 January 2013 - 03:50 PM
Error messages can be very handy…

bios:338: [string "logger"]:77: '(' expected

this tells us that in the file logger, on line 77 that the compiler expected to see a ( but there wasn't one
Robin1225 #6
Posted 12 January 2013 - 03:53 PM
EDIT: Found it maybe… or maybe found one…. in checkLogs()


if turtle.compareTo(i)==true

should be

if turtle.compareTo( i ) then

you missed the then

same issue in checkSaplings() and fillFurnace()

I corrected those mistakes, but the same error is occuring.
LOL. I know how i made those mistakes :P/> I'm more familar with java and if statements in java look like
if (this==true) etc.
Robin1225 #7
Posted 12 January 2013 - 03:56 PM
Error messages can be very handy…

bios:338: [string "logger"]:77: '(' expected

this tells us that in the file logger, on line 77 that the compiler expected to see a ( but there wasn't one
Thanks for the tip! :D/> I fixed a lot of other errors (I keep forget the word function)
However, now error is
logger:171: attempt to call nil
theoriginalbit #8
Posted 12 January 2013 - 04:11 PM
on line 171 the function checkTrees() doesn't exist… change it to checkTree()
Robin1225 #9
Posted 12 January 2013 - 05:38 PM
Well.. At least the errors are gone! The turtle is not moving according to plan though :(/>
Thanks for all the help TheOriginalBit!!
theoriginalbit #10
Posted 12 January 2013 - 05:39 PM
no problems :)/>
Robin1225 #11
Posted 12 January 2013 - 05:46 PM
Hmm… Do you have any suggestions for this new problem? :P/>
the checkTree() function calls for
turtle.up(6)
and turtle.forward(4) etc.
apparently the turtle api does not accept any parameters. Does that mean I have to make loops for all of them?
crazyguymgd #12
Posted 12 January 2013 - 05:50 PM
Yup that's exactly what you have to do. But you can also create a new function that does take parameters and loops x number of times, and then just call that function.
Robin1225 #13
Posted 12 January 2013 - 06:10 PM
Yup that's exactly what you have to do. But you can also create a new function that does take parameters and loops x number of times, and then just call that function.
Thanks for the advice!! I added it, and it works like a charm now :)/> Thanks to you both!
crazyguymgd #14
Posted 12 January 2013 - 06:11 PM
cool :)/>
Robin1225 #15
Posted 12 January 2013 - 06:23 PM
Well… Yet Another Error :P/> Didn't think I was this bad at scripting XD
I changed a lot of the code so for Line 163 my current code is : if turtle.getItemCount()<64 then
Error is
Logger: 163: Expected Number.

Edit: Forgot Parameters. Fixed
theoriginalbit #16
Posted 12 January 2013 - 06:24 PM
turtle.getItemCount requires an argument telling it which slot…
Robin1225 #17
Posted 12 January 2013 - 06:31 PM
So far so good…. Its supposed to be a charcoal farming turtle to generate enough fuel for other turtles :P/>
If any problem arises that I can not solve, I will post here :D/>
Edit: Successfully ran through an entire loop!! Thanks Guys!!