monday Posted November 6, 2014 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
MTA Team botder Posted November 7, 2014 MTA Team 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. GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
Dealman Posted November 7, 2014 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 If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
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