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

error with an if statement

Started by hipie1234567, 19 April 2013 - 08:19 AM
hipie1234567 #1
Posted 19 April 2013 - 10:19 AM
Hello, I'm a noob who can't figure out why the else part of an if/there/else statement won't work. I don't know how to use paste-bin so I'll just type my simple code for trying to make a tree farming robot. p.s.the error is a bios:338 on line 10 which is where the else is and it says an = is expected.
turtle.compare()
if true then
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
reboot
else
turtle.dig()

then i tell it to keep digging up the tree.
Bubba #2
Posted 19 April 2013 - 10:31 AM
Using pastebin is simple. Go to their website, copy/paste your code, hit submit. Done.

Second, the reason your code is not working is due to the line where you have "reboot". That is not a function, and even if it were you need parentheses to make it run.

Another thing you need is an end to the if statement.


if condition then
  --Do stuff
  --What purpose does os.reboot() have here anyway? Use a while loop.
else
  --Do other stuff
end
remiX #3
Posted 19 April 2013 - 10:31 AM
The main reason would be that you did not end the if statement.
And if statement goes like this:
if <condition> then
	-- Do this
else
   -- Do that
end -- need this
(applies for loops, functions, can't think of what else if there are more)

In your case, you're checking if true == true then do the code, but true is ALWAYS equal to true.
I would guess you wanted to check if turtle.compare was true:
if turtle.compare() then -- same as if turtle.compare == true then
	turtle.turnLeft()
	turtle.turnLeft()
	for i=1,4 do turtle.forward() end -- loop! :D/>/>/>
else
	turtle.dig()
end

What that loop does is it does turtle.forward, 4 times.

EDIT:
Ninja'd by what? A few seconds?!
hipie1234567 #4
Posted 19 April 2013 - 10:40 AM
thanks for the help and to your response remix, i did put an end to it i just didn't want to type that and i know that works because i already looked on here and fixed it possibly i may have the wrong end and again I'm just noob. again thanks for the help this just taught me like 12 things.
hipie1234567 #5
Posted 19 April 2013 - 10:50 AM
oh yeah by the way if you are still on this page how do you extract files from a floppy?
Bubba #6
Posted 19 April 2013 - 11:00 AM
oh yeah by the way if you are still on this page how do you extract files from a floppy?

As in copy them from a floppy?

Use fs.copy

fs.copy("/disk/fileToCopy", "/newFileCreated")
hipie1234567 #7
Posted 19 April 2013 - 11:25 AM
thank you i luvs your knowledge oh and could you check out the other topic post
LNETeam #8
Posted 20 April 2013 - 01:19 AM
Also your reboot should be os.reboot()