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

missing 'then' ?!

Started by HennoTM, 01 January 2015 - 03:34 PM
HennoTM #1
Posted 01 January 2015 - 04:34 PM
Hey there!

Today i wanted to make a program for my farming turtle.
It's already pretty good, but i wanted to make it better (of course).
So i tried to use turtle.getItemDetail() and tried in a "Test" program how to use it.
My text is this:


data = turtle.getItemDetail()

if data.name = minecraft:wheat_seeds then
write("There are seeds!\n")
end

When i run the program the computer writes an error:


bios:366: [string "Test"]:3: 'then' expected

I wrote a 'then' so i don't understand the mistake.
Maybe you can help me…
Lyqyd #2
Posted 01 January 2015 - 11:58 PM
Ah, no, it says it expected "then", not that you're missing "then". This error is covered in the Common Errors section of the Read This Post Before Asking Questions topic that you read all the way through before asking a question.
wieselkatze #3
Posted 02 January 2015 - 01:03 AM
To clarify - you do actually have a malformed if-then expression there.
One error is already covered in Lyqyd's post - you're using '=' instead of '=='.
Your other mistake is comparing data.name to minecraft:wheat_seeds - that should be a string; meaning that it should either be marked in double or single quotation marks.
The correct code would look like this:


data = turtle.getItemDetail()

if data.name == "minecraft:wheat_seeds" then
  write("There are seeds!\n")
end

By the way: Instead of using a write() with \n at the end of the string, you could also just use print().
Edited on 02 January 2015 - 12:04 AM