Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Archived

This topic is now archived and is closed to further replies.

  • 0
Heavy Cat

Logic Help

Question

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'

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

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

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.