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 » Scripting Helpers
Home Search
 

Re: A question about arrays

Previous Thread :: Next Thread 
NinjaShadow1 is not online. NinjaShadow1
Joined: 03 Mar 2009
Total Posts: 2689
22 Feb 2012 08:22 PM
I have an array, lets say that it's
myArray={"A","B","C"}

How do I find the key of item "B" ?
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
22 Feb 2012 08:25 PM
You mean "table"?

myArray[2]
Report Abuse
lordyoman is not online. lordyoman
Joined: 10 Jun 2010
Total Posts: 426
22 Feb 2012 08:27 PM
It's called a table...
Report Abuse
NinjaShadow1 is not online. NinjaShadow1
Joined: 03 Mar 2009
Total Posts: 2689
22 Feb 2012 08:27 PM
Arrays and tables are the same thing.

I mean, how do I find that "B" is number 2?
Report Abuse
NinjaShadow1 is not online. NinjaShadow1
Joined: 03 Mar 2009
Total Posts: 2689
22 Feb 2012 08:28 PM
If you go to (almost) any other language (Even VB) it's called an Array
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
22 Feb 2012 08:31 PM
Well, it's called a table in Lua, so just remember that to prevent confusion. Anyway, you can do that with a loop:

table = {"A", "B", "C"}

for i, v in pairs(table) do
if (v == "B") then
print(i)
end
end

Will print "2"
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
22 Feb 2012 09:00 PM
At blockoo

Its an array.
A table is an empty dictionary, an array is a dictionary with elements. Matrix is a dictionary with multiple arrays?
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
22 Feb 2012 09:35 PM
No, they're interchangeable terms for the most part. Think about a real-life table. Even if you put things on it, you still call it a table, right?
Report Abuse
bballer13sn is not online. bballer13sn
Joined: 03 Jun 2009
Total Posts: 2490
22 Feb 2012 09:45 PM
OMG PEOPLE! Table is the Lua term for it, but MOST people call it an array...It DOESN'T MATTER which of the two INTERCHANGEABLE terms is used. As for your question, you'd do this:

arrayName[2]
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
22 Feb 2012 09:49 PM
> No, they're interchangeable terms for the most part. Think about a real-life table. Even if you put things on it, you still call it a table, right?

Wrong type of table broski. Look up mathematical tables.

Also an array is a multi-dimensional array, not a table with mutliple arrays.
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
22 Feb 2012 09:50 PM
@bballer
Your explanation of table vs. array is correct, but that's not what he asked for. He wanted to be able to get the index number of "B".
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
22 Feb 2012 09:51 PM
"Also an array is a multi-dimensional array"

...what?
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
22 Feb 2012 09:51 PM
A matrix* lo siento
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
22 Feb 2012 09:53 PM
But table = array, yes?
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
22 Feb 2012 10:02 PM
The most common response is that a table is empty whereas an array has elements. Personally I always thought the difference was that arrays have infinite dimensions/indices and can hold any type of data value. Whereas tables have a defined size and data-type ( `int[] tab=new int[5];` ) however it really shouldn't matter.
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
23 Feb 2012 12:07 AM
Well, that's annoying. I always thought of an array as a table with only numeric indices. To the Wiki! Yep, I'm right >=D
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
23 Feb 2012 12:28 AM
@merlin11188

You are right and I was actually going to point it out.


Arrays and tables aren't the same thing. Arrays are values ordered in a certain order, while Lua tables are data structures that consist of a pair of keys and values, both the key and the value being able to be any kind of value except nil.
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
23 Feb 2012 02:50 AM
Almost forgot :P Tables are not aren't even a data structure
http://www.lua.org/pil/11.html
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