Jump to content

Search a table position with a string or something?


Recommended Posts

Posted

Hey, it is possible to search an item position on a table, by a string?

mytable = {

[1] = {account1,name1}

[2] = {account2,name2}

}

example i want to get a position on the table for example i want to get [1] searching by it name or account

How can i make it?

"El conocimiento jamás debe detenerse, por que es lo único que nos salvará cuando no nos quede más".

Att: -|TG|-Mister[Q]<.

Posted

Loop the table and compare the strings.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Not sure what you mean. You could do what Solidsnake14 said if that's what you mean, or from my understanding use a string as the key.

Example:

my_table = { 
    ['index 1'] = "Value", 
    ['Another Index'] = "Value 2" 
} 
-- You could use my_table["index 1"] to get "Value" 

Posted
for index, data in ipairs ( mytable ) do 
    if ( data [ 1 ] == "myAccount" ) then 
        outputChatBox ( index ) 
    end 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...