I\'m working with this:
chars = {
[\"Nigo Astran\"]=\"1\",
[\"pantera\"]=\"2\"
}
nchar = (chars[$name])+1
<
the best way to do that is like this
local autoreply={
['hey']='hi',
['how are u']='am fine what about u?',
['how r u']='am fine what about u?',
['how are you']='am fine what about u?',
['sleep']='rockabye bayby good dreems',
['السلام']='وعليكم السلام ورحمة الله وبركاته',
}
local keys={'hey','how are u','how r u','how are you','sleep','السلام'}
function getValueFromKey(table,key)
for k,v in ipairs(keys)do
if string.find(string.upper(key),string.upper(v)) then return table[v] end
end
return false
end
I don't think there is anything more efficient than looping over the entries in the table using pairs
and comparing the keys.
you can do that using something like this
function get_key_for_value( t, value )
for k,v in pairs(t) do
if v==value then return k end
end
return nil
end
Then you'd use it like this:
local k = get_key_for_value( chars, "1" )
If you find yourself needing to get the key from the value of a table, consider inverting the table as in
function table_invert(t)
local s={}
for k,v in pairs(t) do
s[v]=k
end
return s
end