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

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'

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 1
  • Solution
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

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

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