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

[Error] I have a query about this program

Started by lordsyca, 08 September 2012 - 12:38 AM
lordsyca #1
Posted 08 September 2012 - 02:38 AM
I get an error at Line number 10, stating that I need to put an equals sign there. I've looked and tried rewriting this, but I can't seem to grasp the problem.



local time = os.time()
time = textutils.formatTime(time, false)
print ("Enter your login name:")
local name = read()
sleep(.5)
term.clear

if name == "Syca" or "lordsyca" or "chris" or "appa" or "Appa" or "Chris" then
  print ("Enter your password:")
  local password = read("*")
  sleep(.5)
  term.clear
	if password == "Izzisixx6" then
	  print("Welcome ", name, " The current time is ", time)
	else
	  print ("Wrong Password")
	  os.reboot
	  end
end
if name == "Izzi" or "momo" or "izzi" or "Momo" or "Zavrina" or "zavrina" then
  print ("Enter your password:")
  local password = read("*")
  sleep(.5)
  term.clear
	if password == "Izzisixx6" then
	  print("Welcome ", name, " The current time is ", time)
	  sleep(1)
	  shell.run(izzi)
	else
	  print ("Wrong Password")
	  os.reboot
	  end
end
else
  print ("Unknown User")
  sleep(3.5)
  os.reboot
Kingdaro #2
Posted 08 September 2012 - 02:45 AM
Your if statement is wrong. Instead of using names alone, you have to compare the name variable to all possible names. What I mean is:

if name == "Syca" or "lordsyca" or "chris" or "appa" or "Appa" or "Chris" then

should be


if name == "Syca"
or name == "lordsyca"
or name == "chris"
or name == "appa"
or name == "Appa"
or name == "Chris" then

It could all be on one line, however I find this easier to read.

If you don't want to a bunch of "or name ==" bits, you could make a string with all the possible names and then check if a certain name is in the string using :match() with special formatting.


local possibleNames = 'Syca;lordsyca;chris;appa;Appa;Chris;'

if possibleNames:match(name .. ';') then
  --your code if a name is valid
end
lordsyca #3
Posted 08 September 2012 - 02:59 AM
I've tried both of those I still get "[string "startup"]:14: '=' expected" error.
Kingdaro #4
Posted 08 September 2012 - 03:02 AM
OH, I see it.

"os.reboot" should be "os.reboot()"
lordsyca #5
Posted 08 September 2012 - 03:04 AM
OH, I see it.

"os.reboot" should be "os.reboot()"

Wow I feel stupid, ha ha. Thanks, I always forget those () on somethings.