I'm making a program that uses random words. I'm not talking about "randomly generated words". What I mean is if you type in "test" it will come up as "Hi", or "Hello" with a 50-50 chance.
4 replies to this topic
#1
Posted 05 September 2014 - 07:32 PM
#2
Posted 05 September 2014 - 07:52 PM
local known = {
test = { "Hi", "Hello" },
}
local input = read()
if known[ input:lower() ] then
print( known[ input ][ math.random( 1, #known[ input ] ) ] )
else
print( "I don't understand!" )
end
Does this help?
Edited by KingofGamesYami, 05 September 2014 - 07:52 PM.
#3
Posted 05 September 2014 - 09:07 PM
KingofGamesYami, on 05 September 2014 - 07:52 PM, said:
local known = {
test = { "Hi", "Hello" },
}
local input = read()
if known[ input:lower() ] then
print( known[ input ][ math.random( 1, #known[ input ] ) ] )
else
print( "I don't understand!" )
end
Does this help?
Extra comma in the end of the second line
#5
Posted 06 September 2014 - 02:21 AM
It's a good way of doing it, but one small change I'd make:
It saves having to use :lower() over and over again later in the code (something you forgot to do!).
local input = read():lower()
It saves having to use :lower() over and over again later in the code (something you forgot to do!).
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











