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

coding error

Started by Liara11, 21 June 2012 - 04:33 PM
Liara11 #1
Posted 21 June 2012 - 06:33 PM
Hi, I'm pretty new to ComputerCraft, and I need some help with a coding error.

Error:

Bios:206: [string "startup"] :8: 'then' expected

I got this for ALL the code I've mad so far, and they are all about the same.
I tried quite a few things, but it still won't work!

the code I'm trying to fix right now:

Spoilerpass = ("Startclan's lights")
tries = 3

print ("welcome")
print (" password: ")
triesnum = 1,tries,1 do
password = read()
if password = (pass) then
print ("acess granted")
else
print ("acess denied try again")
end
end
if triesnum == tries then
print ("acess denied.")
end

pretty simple, but I still can't fix it.
MysticT #2
Posted 21 June 2012 - 06:37 PM
To compare values, you need to use ==, not =.
= assignment
== comparison
Example:

valueA = 10 -- assing the value 10 to valueA
valueB = "Hello" -- assing the value "Hello" to valueB
if valueA == valueB then -- compare valueA and valueB
  -- do something
end

Also, to make a loop, use for or while:

while <condition> do
  -- code
end

for i = 1, 10 do
  -- code
end

Fixed code:

local pass = "Startclan's lights"
local tries = 3

print("welcome")
print(" password: ")
for triesnum = 1, tries do
  local password = read()
  if password = pass then
	print ("acess granted")
	break -- break the loop
  else
	print ("acess denied try again")
  end
end
if triesnum == tries then
  print ("acess denied.")
end
Bossman201 #3
Posted 21 June 2012 - 10:44 PM
If you're trying to increment a for loop by one, then you don't need the third parameter as it increments by one by default.

EDIT: Also you left 'for' out of your code on line 6, which is probably why you got 'then' expected error.