Jump to content




Error: do/then after '= true'


  • You cannot reply to this topic
3 replies to this topic

#1 oWave

  • Members
  • 23 posts

Posted 26 June 2013 - 03: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?

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 26 June 2013 - 05:01 PM

Split to new topic.

#3 MudkipTheEpic

  • Members
  • 639 posts
  • LocationWhere you'd least expect it.

Posted 26 June 2013 - 05:27 PM

For assignment of variables, use "=".

For comparison, use "==".

So while turtle.compare()==true do instead.

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 26 June 2013 - 05: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users