table.SortByMember
From GMod Wiki
| Function | |
| Syntax |
table.SortByMember( Table table, String member, Function comparative ) Where is this used? |
| Description: | |
| Sorts a table into descending order by member. | |
| Returns: | nil |
| Part of Library: | Table |
| Realm: |
|
| BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=Table.SortByMember]Table.SortByMember [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
| Description | Sort the values of a Table by member. |
|---|---|
| Used on | |
| Code | local playerinfo = {} local playertable = {} for _,player in pairs(player.GetAll()) do playerinfo = {Name = player:Nick(), ID = player:EntIndex()} // This creates a table with the members "Player" and "ID." table.insert(playertable, playerinfo) // This inserts a player's information ("Name" and "ID") for each player into "playertable." end table.SortByMember(playertable, "ID") // Sort the table numerically by the member "ID". This seems to be in descending order. PrintTable(playertable) // Print the table into our console. // If you wish to sort the table in ascending order, then do this. table.SortByMember(playertable, "ID", function(a, b) return a > b end) PrintTable(playertable); // Print the table into our console. |
| Output | Prints a Table in order by member into the console. |
Additional Notes
- N/A