Exabyte the Protogen 0 Posted December 20, 2017 Share Posted December 20, 2017 I need help with something here is my code: local computer = require ("computer") Print("What's The Password?") local password = io.read() if password = 123 print("Password Accepted") end else print("Password Denied") os.sleep(2) computer.stop() The error is then expected near = what do i do? anywhere i could think of i tried putting 'then' Quote Link to post Share on other sites
1 Solution Molinko 43 Posted December 20, 2017 Solution Share Posted December 20, 2017 local computer = require ("computer") print("What's The Password?") local password = io.read() -- # HERE is the missing end. Also, use the '==' for equality and single '=' for assignment -- # Also to note, io.read returns a string. password == 123 will error comparing a string to a number. -- # Use password = tonumber(password) or convert the right side of the comparison to a string with tostring(123) -- # if password == "123" then ... or password == tostring(123) ... or tonumber(password) == 123 ... if password == "123" then -- # I just put the pass in quotes to keep it simple. print("Password Accepted") -- end # bad end here too else print("Password Denied") os.sleep(2) computer.stop() end -- # end goes here Quote Link to post Share on other sites
I need help with something
here is my code:
local computer = require ("computer")
Print("What's The Password?")
local password = io.read()
if password = 123
print("Password Accepted")
end
else
print("Password Denied")
os.sleep(2)
computer.stop()
The error is
then expected near =
what do i do?
anywhere i could think of i tried putting 'then'
Link to post
Share on other sites