monday Posted November 6, 2014 Share Posted November 6, 2014 Is there any easy way to find it? Let's say that I have a table like this: mytable = {999, 1001, 996, 991} And I'd like to find the position of 996 by something like: number = tableMagicFind(mytable, 996) --number would be 3 Link to comment
MTA Team botder Posted November 7, 2014 MTA Team Share Posted November 7, 2014 for index, value in pairs(mytable) do if (value == 996) then return index end end You can move that to a function and replace mytable and 996 with function parameters. Link to comment
Dealman Posted November 7, 2014 Share Posted November 7, 2014 You can also do it like this; local selectedIndex = mytable[3]; -- Will return 996 It works similarily if your table has another table inside of it. IE; local myTable = {{1, 2, 3}, {"A", "B", "C"}, {1, 2, 3}}; local selectedIndex = myTable[2][3]; -- Will return C Edit: Nevermind, just saw that you wanted to find the position of it Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now