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

[Lua] [Error] Unexpected symbol

Started by lordxarus, 07 February 2013 - 05:57 AM
lordxarus #1
Posted 07 February 2013 - 06:57 AM
I have an unexpected symbol error on line 131 the line is actually; if rStart == 1 or == 2 or == 3 or == 4 or == 5 then. By the way not sure why the line encoding looks so messed up.


print "Put a sapling in slot 1 and 15."
print("")
print("")
print("")
print("")
print "Press any key to continue"
os.pullEvent("key")
print("")
print("")
print("")
print("")
print("")
print "Put a log in slot 14 note: this has to be the same as the sapling."
print("")
print("")
print("")
print("")
print "Press any key to continue"
os.pullEvent("key")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print "Put bonemeal into slot 2 and 16."
print("")
print("")
print("")
print("")
print("Please make sure the turtle has at least 50 fuel or it will not be able to run!")
print("")
print("")
print("")
print("")
print "Start the program?  Make sure that all of the items are in the correct places!"
os.pullEvent("key")
-- END OF THE INSTRUCTIONS!
-- Varibles
local bExit = false -- For the ending of the program in the the checkSaplings and checkMeal statements.  Also used in the while statement at the end.
local numCut = 1 -- This i
local wood = 1
-- Functions with if statements

local function turtleRefuel()
	turtle.select(14) --This selects wood
		 if turtle.getFuelLevel() <= 50 then
		 if turtle.compareTo(3) == true then
	   turtle.select(3)
		  turtle.getItemCount(3)
	wood = turtle.getItemCount(3)
	turtle.refuel(wood)
			else
				print("Could not refuel")
	bExit = true
		 end
	end
end  
local function checkSaplings()
   turtle.select(1)
	  if turtle.compareTo(15) == false then --Slot 15 is saplings
	  print("Check the saplings.  Either could not check saplings are none or there are none left.")
   bExit = true
	  else
	end
end
local function checkMeal()
   turtle.select(2)
	  if turtle.compareTo(16) == false then --Slot 16 is bonemeal
	  print("Check the bone meal.  Either could not check bone meal or there none is left.")
   bExit = true
	  else
	end
end

-- Normal Functions
local function plantTree()
   turtle.select(1)
   turtle.place()
   sleep(.75)
   turtle.select(2)
   turtle.place()
end
local function cutTree()
   turtle.dig()
   turtle.forward()
   turtle.suck()
   turtle.digUp()
   turtle.suck()
   turtle.up()
   turtle.digUp()
   turtle.suck()
   turtle.up()
   turtle.digUp()
   turtle.suck()
   turtle.up()
   turtle.digUp()
   turtle.suck()
   turtle.up()
   turtle.digUp()
   turtle.suck()
   turtle.up()
   turtle.digUp()
   turtle.suck()
   turtle.up()
   turtle.digUp()
   turtle.suck()
   turtle.up()
   turtle.digUp()
   turtle.suck()
   turtle.up()
end
local function returnToStart()
	 for rStart = 1,5 do
	 print(rStart)
	 if rStart == 1 or == 2 or == 3 or == 4 or == 5 then
	  while turtle.down() == false do
	  turtle.down()
		if rStart == 5 then
				 turtle.back()	  
		rStart = 6
		  if rStart == 6 then
			 turtle.back()
		   if rStart == 6 then
		end
	 end
   end	
		 end
   end
   end
end

-- While statement (actual program that is executed)
while bExit == false do
checkSaplings()
checkMeal()
turtleRefuel()
plantTree()
cutTree()
returnToStart()
end
Doyle3694 #2
Posted 07 February 2013 - 07:53 AM
== needs a number on both sides, though, I'm pretty confused about what that for loop a couple of lines above it is for
Engineer #3
Posted 07 February 2013 - 07:55 AM
Try this:

if rStart > 0 and rStart < 6 then

In your syntax:

if rStart == 1 or rStart == 2 or rStart == 3 or rStart == 4 or rStart ==5 then

You have to retype your variable each time.
This is so you can do something like this:

if rStart == 1 or x == 2 then

EDIT:

Please replace the top piece with this. It saves some lines:

print("put your sapling in slot 1 and 15")
local p1, p2 = term.getCursorPos()
term.setCursorPos(p1, p2 + 4)
print("Press any key to continue")
os.pullEvent("key")
term.setCursorPos(p1, p2 + 13)
print("Put bonemeal in slot 2 and 16")
term.setCursorPos(p1, p2 + 18)
print("something with fuel")
term.setCursorPos(p1, p2 + 23)
print("start the program")
os.pullevent("key")

A bit messy but it should work. If you want to clear a screen you could use:

term.clear()
term.setCursorPos(1,1)

You can ofcourse make this a function and then recall it with 1 line instead of two. I would use a function only if you are going to recall it more then twice.
Edited on 07 February 2013 - 07:07 AM