11 posts
Posted 23 April 2012 - 08:36 PM
so um… how exactly do i edit this code so:
the user inputs anything other then a valid input, X happens
for example
is minecraft cool?
y
n
>
*user types* "asdfphdsf"
print ("what?")
11 posts
Posted 23 April 2012 - 08:37 PM
also *input , for some reason firefox's spell check doesnt work on this site.
92 posts
Posted 23 April 2012 - 09:16 PM
if input=="y" then
.....
elseif input=="n" then
.....
else
print("what?")
end
Also, you can edit your post. No need to double post.
1111 posts
Location
Portland OR
Posted 23 April 2012 - 09:17 PM
Bah ninja'd :)/>/> ….
Just an if elseif else statement. so..
while true do
print ("Is minecraft cool??")
input = read()
if input == y then
print ("woot!!")
elseif input == n thne
print ("your lame")
else
print ("huh? Try again..")
end
end
Edited on 23 April 2012 - 07:17 PM
454 posts
Location
London
Posted 23 April 2012 - 09:28 PM
I'd recommend using a table as a set over an elseif chain for this.
local valid = {
['y'] = true,
['n'] = true
}
local input = read()
if not valid[input] then
-- bad input
end
...