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

[Error] 'then' expected

Started by f1ngal, 22 September 2012 - 11:02 AM
f1ngal #1
Posted 22 September 2012 - 01:02 PM
I am fairly new to computercraft and need help, it says:

bios:206: [string "startup"]:3: 'then' expected
(edit startup)
print (" Enter Password Please: ")
x = "redapple"
if x = true 'then'
redstone.setOutput ("left", true)
sleep(10)
redstone.setOutput ("left", false)
os.reboot

if x = false 'then'
textutils.slowprint (" Nice Try Hacker ")
os.reboot
end


what did I do wrong?
Kazimir #2
Posted 22 September 2012 - 01:47 PM
write with syntax
print ("Enter Password Please: ")
x = read()
if x == "redapple" then
  redstone.setOutput ("left", true)
  sleep(10)
  redstone.setOutput ("left", false)
  os.reboot()
else
  textutils.slowprint ("Nice Try Hacker")
  os.reboot()
end
f1ngal #3
Posted 22 September 2012 - 01:52 PM
What does that mean? please explain "write with syntax"
Kazimir #4
Posted 22 September 2012 - 01:55 PM
What does that mean? please explain "write with syntax"
Wanted to say "write with syntax highlighting"
Fatal_Exception #5
Posted 22 September 2012 - 02:05 PM
- Single equals (=) for assignment.
- Double equals (==) for comparison.

- Then should not be in quotes.
- os.reboot is a function so it needs parentheses after it: os.reboot()
- a string and a boolean will never be directly equal.
- You're missing an 'end' after the first If block
- You will never see the text in the second if, because it will instantly reboot.

This code will run, but it's not very useful in its current state.

print (" Enter Password Please: ")
x = "redapple"
if x == true then
  redstone.setOutput ("left", true)
  sleep(10)
  redstone.setOutput ("left", false)
  os.reboot()
end

if x == false then
  textutils.slowprint (" Nice Try Hacker ")
  os.reboot()
end

I presume you wanted something like:

print (" Enter Password Please: ")
x = "redapple"
input = read()  -- Read text from keyboard and store it
if x == input then  -- If the user input matches our password
  redstone.setOutput ("left", true)
  sleep(10)
  redstone.setOutput ("left", false)
  os.reboot()
else   -- It didn't match
  textutils.slowprint (" Nice Try Hacker ")
  sleep(2)
  os.reboot()
end
f1ngal #6
Posted 22 September 2012 - 02:17 PM
thanks a lot! especially the hasty response, but I still get bios:206: [string "startup"]:3: 'then' expected
sjele #7
Posted 22 September 2012 - 06:08 PM
if something == "this" then --Correct 
if something == "this" "then" --Wrong

then does not require "'s or single qoutes.
f1ngal #8
Posted 23 September 2012 - 09:02 AM
thanks