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

I have problem with program for password in CraftOS 1.6

Started by Fufciak, 20 August 2015 - 07:58 PM
Fufciak #1
Posted 20 August 2015 - 09:58 PM
Hi i'm new in forum and i from poland
Please understand my English because i can't write very well and say
I have one problem with program
Here :
  • os.pullEvent = os.pullEventRaw
  • login = Fufciak
  • Pass = Pisze
  • while true do
  • term.clear()
  • term.setCursorPos(1, 1)
  • print("Witaj w systemie FufuOS")
  • print("Co chcesz zrobic?")
  • print("[1] Zaloguj")
  • print("[2] Wylacz komputer")
  • write("> ")
  • input = read()
  • if input == "2" then
  • os.shutdown()
  • elseif input == "1" then
  • print("Prosze sie zalogowac")
  • write("Uzytkownik: ")
  • Uzytkownik = read()
  • write("Haslo: ")
  • Haslo = read("*")
  • if (Uzytkownik == login) and (Haslo == Pass) then
  • print("Zalogowano!")
  • break
  • elseif
  • print("Nieprawidlowe dane!")
  • sleep(2)
  • os.shutdown()
  • end
  • end
  • end

​Any one can correct me program ?

I will be very thankfull

:rolleyes:/>
Lupus590 #2
Posted 20 August 2015 - 10:44 PM
What is the error?
The_Cat #3
Posted 20 August 2015 - 10:46 PM
Its becuase you are not comparing it to a string, try this:

login = "Fufciak"
Pass = "Pisze"
Edited on 20 August 2015 - 08:51 PM
Lupus590 #4
Posted 20 August 2015 - 10:49 PM
Good spot The_Cat, that like was it. Other than some bad practice and a useless while true, I see no other errors.
Edited on 20 August 2015 - 08:49 PM
Dog #5
Posted 21 August 2015 - 12:14 AM
There's also appears to be an unnecessary 'break' near the end of the code (just before the elseif)
Edited on 21 August 2015 - 12:25 AM
Lyqyd #6
Posted 21 August 2015 - 12:50 AM
That's necessary unless the loop is excised. And the loop should be left in, instead getting rid of the reboot call.
Dog #7
Posted 21 August 2015 - 02:25 AM
Oh, silly me - I didn't even see the loop - thanks for pointing that out
Edited on 21 August 2015 - 12:30 AM
Fufciak #8
Posted 21 August 2015 - 05:13 AM
Its becuase you are not comparing it to a string, try this:

login = "Fufciak"
Pass = "Pisze"
I correct that are you write and i have the same error
Dog #9
Posted 21 August 2015 - 05:29 AM
The elseif around line 24 should just be else
Fufciak #10
Posted 31 August 2015 - 02:18 PM
Dog the same problem
Anyone can correct finally my try write program ?
Dog #11
Posted 31 August 2015 - 04:16 PM
Please post the code as it is now so I can see the changes you've made.
Exerro #12
Posted 31 August 2015 - 05:48 PM
The error you're getting is saying that it's expecting a 'then' after an 'elseif' or 'if' condition. If you have an 'elseif' on its own, followed by a function call, it will assume the function call is part of the condition. Take these as examples:

elseif
	f()
	a()


elseif f() then
a()

The first one will know that it needs a 'then', but it'll say it needs it after f() because f() is just like a condition (like the second one). That means you'd get the error on line 3 of the first example, for example, because that's the first thing after the condition, which is where the 'then' should be.
Edited on 31 August 2015 - 03:48 PM