Lua find a key from a value

前端 未结 3 1972
渐次进展
渐次进展 2020-12-03 19:43

I\'m working with this:

    chars = {
         [\"Nigo Astran\"]=\"1\",
         [\"pantera\"]=\"2\"
         }

   nchar = (chars[$name])+1
<
3条回答
  •  误落风尘
    2020-12-03 20:17

    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
    

提交回复
热议问题