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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

[ Content Deleted ]

Previous Thread :: Next Thread 
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
01 Jun 2012 04:10 AM
I am experimenting with tables. How would you make it so that a line of code can check if there is a specific value in the table? e.g

myTable = {"Hi","Hello","World"}

How would you check if "Hello" is in the table, if it is in the table print("Yes").

Can somebody help?
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
01 Jun 2012 04:15 AM
Look how an admin script is built up. It also uses tables. Look at where it checks if the player is in that table.
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
01 Jun 2012 04:30 AM
[ Content Deleted ]
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
01 Jun 2012 11:18 PM
Thank you
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
01 Jun 2012 11:37 PM
Can you help me with this?

local players = {"Hello","Hi","World"}

function findPlayer(name)
for _,v in pairs(players) do
if v:sub(1) == name:sub(1) then
return true
end
end
end

print(findPlayer("W"))

^^^In that script I want to check if there is a word starting with W in the table.^^^

That does nothing but this works:

local players = {"Hello","Hi","World"}

function findPlayer(name)
for _,v in pairs(players) do
if v == name then
return true
end
end
end

print(findPlayer("World"))


Whats wrong?
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
01 Jun 2012 11:47 PM
myTable = {"Hello","Hi","Bye"}
function over_load(index)
if myTable[index] == nil then return
elseif myTable[index] == "Hi" then
return "Yes"
else
over_load(index + 1)
end
end

over_load(1)

Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
01 Jun 2012 11:49 PM
Thanks for your help miz, but I did find another easier way to do it.

local players = {"Hello","Hi","World"}

function findPlayer(name)
for _,v in pairs(players) do
if name == v:sub(1,name:len()) then
return true
end
end
end

print(findPlayer("Wo"))


That will check if the word 'Wo' is in any of the words in the table.
You can also change 'Wo' to any word that is in a word in the table.
Report Abuse
aboy5643 is not online. aboy5643
Joined: 08 Oct 2010
Total Posts: 5458
02 Jun 2012 12:26 AM
local players = {"Hello","Hi","World"}
function findPlayer(name)
for _,v in pairs(players) do
return name == v:sub(1,name:len())
end
end
end
print(findPlayer("Wo"))

Shortened for no reason other than to point out it does the same thing
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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