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

Error: do/then after '= true'

Started by oWave, 26 June 2013 - 02:53 PM
oWave #1
Posted 26 June 2013 - 04:53 PM
Title: Error: do/then after '= true'

I'm working on a little program where I need this:
while turtle.compare() = true do

If I now start the program, I get this error: bios:338:[string: fell]:2: 'do' expected

Here's the full code:

local function FellDown()
  while turtle.select(2) turtle.compare() = true do
	turtle.dig()
  end
end

The same thing happens with "if … =true then"
(Except the error is not with 'then' expected)

Does somebody know why this happens and how to fix it?
Cranium #2
Posted 26 June 2013 - 06:01 PM
Split to new topic.
MudkipTheEpic #3
Posted 26 June 2013 - 06:27 PM
For assignment of variables, use "=".

For comparison, use "==".

So while turtle.compare()==true do instead.
theoriginalbit #4
Posted 26 June 2013 - 06:36 PM
however that being said, you do not even need to put the `== true` in the conditional.


while turtle.compare() do

is equivalent to

while turtle.compare() == true do

just the same as

while not turtle.compare() do
is equivalent to

while turtle.compare() == false do

this is because the compare function returns a boolean, which is what a conditional requires. no point checking a boolean against another boolean, to then get a result of a boolean, just use the initial boolean value.