Jump to content




coding error

computer api

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

#1 Liara11

  • New Members
  • 9 posts

Posted 21 June 2012 - 05: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:

Spoiler

pretty simple, but I still can't fix it.

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 21 June 2012 - 05: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


#3 Bossman201

  • New Members
  • 92 posts

Posted 21 June 2012 - 09: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users