generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Checking if a value is in a Table?

Previous Thread :: Next Thread 
Craftero is not online. 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
EchoReaper is not online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image