Craftero
|
  |
| Joined: 24 Jun 2011 |
| Total Posts: 1451 |
|
|
| 28 Aug 2015 01:23 PM |
Basically, I'm looking for a more efficient, and easy to edit, alternative to this:
if name== ("Tom") or name== ("Bob") or name == ("Len") or name == ("George") or name == ("David") or name == ("Sam")then
--Some code
elseif name == ("Sally") or name == ("Jane") or name == ("Lucy")
--Some code
end
I was wondering whether Tables could be used to make this more efficient, but perhaps there is a better solution.
Any help or advice would be greatly appreciated. If I have not made myself clear as to what I'm trying to accomplish here, please let me know. |
|
|
| Report Abuse |
|
|
|
| 28 Aug 2015 01:24 PM |
t = {"a","b","c"}
function tableContains(t, value) for i,v in next,t do if v == value then return true end end end
print(tableContains(t, "c")) > true print(tableContains(t, "d")) > false
|
|
|
| Report Abuse |
|
|
Craftero
|
  |
| Joined: 24 Jun 2011 |
| Total Posts: 1451 |
|
|
| 11 Sep 2015 11:56 AM |
| Is this the most efficient way of doing this? |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2015 11:57 AM |
The most efficient way is this:
local Table = {["A"] = true, ["B"] = true, ["C"] = true}
if Table["A"] then |
|
|
| Report Abuse |
|
|