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

[Lua][Help] Making a program

Started by Xiges, 08 December 2012 - 12:27 PM
Xiges #1
Posted 08 December 2012 - 01:27 PM
So, I've written a basic program that uses the built in "tunnel" command, yet I keep getting errors and cannot for the life of me figure them out, since I am very new to coding. Would anyone please be kind enough to review my code?


for i = 1,16 do
  shell.run("tunnel", "64")
  if i = 1, 3, 5, 7, 9, 11, 13, 15 then
  turtle.turnRight()
    for o = 1,3
	  turtle.dig()
	  turtle.forward()
    end
    turtle.turnRight()
  if i % 2 then
  turtle.turlLeft()
    for o = 1,3
	  turtle.dig()
	  turtle.forward()
    end
    turtle.turnLefT()
end
turtle.turnRight()
for i = 1, 45 do
  turtle.dig()
  turtle.forward()
end


Currently it's telling me it's expecting a 'then' at line 3.
Cranium #2
Posted 08 December 2012 - 01:48 PM
Your if statement has waaaay too many arguments.
I think you want it to read:

if i = 1 or i == 3 or i == 5 or i == 7 or i == 9 or i == 11 or i == 13 or i == 15 then
You also need to add two 'end's to your code. To close each 'if' statement.
There's also several spelling/capitalization errors in your statements, but I'm sure you can work those out.
OmegaVest #3
Posted 08 December 2012 - 01:50 PM
OOOOOOOOOKKKKKKKAAAAAAAAAYYYYYYYYY.

Let's start from the beginning.

First, when you compare in a conditional statement (if, else, elseif, while, etc.), you use == to denote "is equal to". And, for every number you have on line three, you either need to use the operator "or", and make each number have its own i==#, or a separate if statements.

On the other hand, it would be easier to use code you already have.


for i = 1, 16 do
   shell.run("tunnel", 64) -- That should work as well as the quoted version, I think.
   if not i%2 then  -- Even numbers, good, but you needed the "not", because otherwise it's always "true"
      -- Code from if-block
   else   -- This will select anything odd-numbered.
      -- code from the if i==1, 3, 5, 7 etc if-block
   end
   turtle.turnLeft()  --  Watch your shift-finger.
end
  -- Continue code

If you already know whether something is even, find out if it isn't, is basically what I'm saying.
Xiges #4
Posted 08 December 2012 - 02:48 PM
Thanks much guys, it works! :D/>