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

[Error] Trouble with "while condition do"

Started by Sscchhmueptfter, 12 February 2013 - 10:24 PM
Sscchhmueptfter #1
Posted 12 February 2013 - 11:24 PM
Title: [Error] Trouble with "while condition do"

Hello, the following program results in the error "bios:338: [string "startup"]:5: 'do' expected" and i'm unable to fix it. Changing line 5 to "while 1=1 do" still yielded the same error message. Any ideas why?

edit: Finally figured this out, it needed to be "==" instead of "=". But I still have no idea why, shouldn't "integer=integer" be true or false?
Spoiler
-- coal in slot 16
i = 0
while true do
if turtle.getFuelLevel()>i*2+500 then
  while turtle.getItemCount(15)=0 do
   turtle.digDown()
   turtle.suckDown()
   turtle.digUp()
   turtle.suckUp()
   while not turtle.forward() do
	turtle.dig()
	turtle.suck()
   end
   i=i+1
  end
  turtle.turnRight()
  turtle.turnRight()
end
while i>0 do
  turtle.forward()
  i=i-1
end
turtle.select(1)
turtle.drop()
turtle.select(2)
turtle.drop()
turtle.select(3)
turtle.drop()
turtle.select(4)
turtle.drop()
turtle.select(5)
turtle.drop()
turtle.select(6)
turtle.drop()
turtle.select(7)
turtle.drop()
turtle.select(8)
turtle.drop()
turtle.select(9)
turtle.drop()
turtle.select(10)
turtle.drop()
turtle.select(11)
turtle.drop()
turtle.select(12)
turtle.drop()
turtle.select(13)
turtle.drop()
turtle.select(14)
turtle.drop()
turtle.select(15)
turtle.drop()
turtle.select(16)
turtle.refuel(turtle.getItemCount(16)-1)
turtle.turnRight()
turtle.turnRight()

end

Cranium #2
Posted 13 February 2013 - 02:47 AM
When you are comparing two variables, then you need to use the '==' operation. When you are assigning a new variable, you use the '=' operation.
InputUsername #3
Posted 13 February 2013 - 05:42 AM
Edit: nvm. Listen to Cranium.
Edited on 13 February 2013 - 04:44 AM