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

Unexpected "="

Started by TplayerJ, 08 April 2012 - 08:30 PM
TplayerJ #1
Posted 08 April 2012 - 10:30 PM
Ok so, I'm new to programming in general and only started lua recently, so I'm probably way out my league when trying this, but…
I was writing this program, and I have been getting lists of errors, the most recent error would be
bios:206: [string "treeagain"]:137: 'end' expectd (to close 'for' at line 81)
Basically, the program is meant to be able towork like excavate, but the dimesions programable and it goes up. There probably is a program like it already, but I was just trying my hand at it.
If someone could help me with the errors it would be most appreciated
 [Sorry don't know how to make spoilers]
[spoiler][code]--Fourth Attempt at a
--Rubber Tree Decimator!

--function function_name()
--this is used to make functions(note to myself)

--Declaring Variables
x = 0
y = 0
z = 0

a = ""
b = ""
c = ""

PosX = 0 --These aren't used for anything
PosY = 0
PosZ = 0

--Prompting User
print("Input length of cube")
a = read()
x = tonumber(a)
print("")
print("--------")
print("")

print("Input width of cube")
b = read()
z = tonumber( :P/>/>
print("")
print("--------")
print("")

print("Input height of cube")
c = read()
z = tonumber©

--Writing Functions to be used
function Forward()
  if turtle.detect() == true then
	 turtle.dig()
  end
  itemcount = turtle.getItemCount(9)
  if itemcount == 64 then
	 for i=1, 9, 1 do
	 turtle.select(i)
	 turtle.drop()
	 end
   end
   turtle.forward()
end

function RightTurn()
  turtle.turnRight()
  Forward()
  turtle.turnRight()
end

function LeftTurn()
  turtle.turnLeft()
  Forward()
  turtle.turnLeft()
end

function GoUp()
  if turtle.detectUp() == true then
	 turtle.digUp()
  end
  turtle.up()
  turtle.turnRight()
  turtle.turnRight()
end

--Meat and Potatoes of the Program
--Initial Forward
turtle.dig()
turtle.forward()

--Looping Methods (functions)
for Y = 1, y, 1 do

  --Inner Loop
  for Z = 1, z, 1 do

	 --Inner Nested Loop
	 for X = 1, x, 1 do
	 Forward()
	 end
	 -- Inner Nested end

  --Deciding Left or Right
  If not z%2 == 0 and not y%2 == 0 == true then
	 RightTurn()  -- this is where it says the error is i think
  end
  If z%2 == 0 and y%2 == 0 == true then
	 RightTurn()
  end
  If not z%2 ==0 and y%2 == 0 == true then
	 LeftTurn()
  end
  If z%2 == 0 and not y%2 == 0 == true then
	 LeftTurn()
  end
end
  --Inner Loop End


GoUp()
end
--Outer Loop End

--Return to Start
--Even or Odd paths
  --Even
  If y%2 == 0 then
	 --Even
	 If z%2 == 0 then
		turtle.turnLeft()
		for Z = 1, z, 1 do
		Forward()
		end
		turtle.turnLeft()
		for X = 1, x, 1 do
		Forward()
		end
	 end
	 --Odd
	 If not z%2 == 0 then
		turtle.turnRight()
		for Z = 1, z, 1 do
		Forward()
		end
		turtle.turnRight()
	 end
  end
  --Even
  else
	 --Even
	 If z%2 == 0 then
		turtle.turnRight()
		for Z = 1, z, 1 do
		Forward()
		end
		turtle.turnRight()
	 end
	 --Odd
	 If z%2 == 0 then
		turtle.turnLeft()
		for Z = 1, z, 1 do
		Forward()
		end
		turtle.turnLeft()
		for X = 1, x, 1 do
		Forward()
		end
	 end
  end
  while not turtle.detectDown() do
	 turtle.down()
  end
Cloudy #2
Posted 08 April 2012 - 10:41 PM
Please use spoiler tags and code tags like this [spoiler][code]

Found your problem.
If (((not(z%2 == 0)) and (not(y%2 == 0))) == true) Then

"Then" should be lower case.
TplayerJ #3
Posted 08 April 2012 - 10:48 PM
Thanks for telling me the spoiler whatchamajig, I'm getting this error now
bios:206: [string "treeagain']:92: unexpected symbol
MysticT #4
Posted 08 April 2012 - 11:18 PM
Lua is case sensitive, so:

If something Then
Else
end
won't work, it's:

if something then
else
end
the "if", the "then" and the "else" has to be lowercase.
TplayerJ #5
Posted 08 April 2012 - 11:21 PM
Thanks, good to know, still new at the lua coding. Still getting errors XD
Luanub #6
Posted 08 April 2012 - 11:37 PM
I'm not sure if it matters or not as Lua doesnt seem to be to picky about this stuff but you do not need the ()'s in the if statements.

so

if (turtle.detect() == true) then

can simply be..

if turtle.detect() == true then

or even easier

if turtle.detect() then
TplayerJ #7
Posted 08 April 2012 - 11:43 PM
It probably doesn't matter about the parenthesis, I just did that because I wasn't sure
cant_delete_account #8
Posted 09 April 2012 - 01:49 AM
It probably doesn't matter about the parenthesis, I just did that because I wasn't sure
The ()s do matter. They shouldn't be there.
cant_delete_account #9
Posted 09 April 2012 - 01:50 AM
And Else and If need to be else and if, Lua is case-sensitive.
TplayerJ #10
Posted 09 April 2012 - 01:51 AM
Shouldn't the program still run with the parenthesis?

*Going to update the code and error name
MysticT #11
Posted 09 April 2012 - 01:52 AM
Yes, they are optional, you can use them if you want, it makes the code more readable sometimes.
TplayerJ #12
Posted 09 April 2012 - 02:13 AM
Ok so I have updated the code, took out all the unnecessary parenthesis I could find as suggested, I also added a couple of "end"s and now my new error is
bios:206: [string "treeagain"]:137: 'end' expectd (to close 'for' at line 81)

I'm goin over it now
cant_delete_account #13
Posted 09 April 2012 - 05:18 AM
Ok so I have updated the code, took out all the unnecessary parenthesis I could find as suggested, I also added a couple of "end"s and now my new error is
bios:206: [string "treeagain"]:137: 'end' expectd (to close 'for' at line 81)

I'm goin over it now
Easy. Add ends until you don't get the error again.
And change all of the Ifs to ifs.
And, if you want, you can do if turtle.detect() then, instead of if turtle.detect() == true then, because turtle.detect() does:

return true