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

[Lua][Question] Assigning more than one string.

Started by PeanutMerchant, 04 May 2012 - 12:41 AM
PeanutMerchant #1
Posted 04 May 2012 - 02:41 AM
I'm coding a simple text password lock for my elevator, i need help with assigning more than one string to my variable.
I just started lua and computercraft so please try to be patient with me

PASSWORD = "Sponge"
HINT = "What you wash things with."
textutils.slowWrite("Type in the PASSWORD, or type <hint>.")
input = read()
if input == PASSWORD then
print("password accepted.")
sleep(2)
os.shutdown()
elseif input == "hint" then
print(HINT)
sleep(2)
os.shutdown()
else print("denied.")
sleep(3)
os.shutdown()
end

What i want is to beable to type the password as either "sponge" or "Sponge" in my terminal, and to beable to type either "hint" , "Hint" or "<hint>" and for it to recognize as the hint.
i've tried:

elseif input == "hint" or "Hint" or "<hint>" then...
and

h = "hint"
s = "Hint"
h == s
elseif input == s then...
with no luck, thank you in advance
Luanub #2
Posted 04 May 2012 - 03:42 AM
Try doing something like this. It will convert what ever the user enters into lowercase


local input = string.lower(read())
PeanutMerchant #3
Posted 04 May 2012 - 12:10 PM
Thank you, this will do!