So I have a 'config 'table: [url]http://pastebin.com/zxZLPWSz[/url]
And I want to iterate through it in order: [lua]
local houses_table = RP_world_properties
table.SortByMember(houses_table, "id")
for k,v in pairs(houses_table) do
//code
end
[/lua]
But once it iterates it goes in a completely different order, how to do this? (note, the iterate function and where the table is stored & defined are seperate files).
You can't really sort a table with non-numeric keys.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/SortedPairsByMemberValue]Global.SortedPairsByMemberValue[/url]
[code]for k, v in SortedPairsByMemberValue( houses_table, "id" ) do
...
end[/code]
This might work.
If not, you're going to have to remove the string keys and just let them be numeric instead.
-snip- doesn't contain numeric indices
[QUOTE=Melted Bu11et;47985328]Use ipairs instead of pairs, I think that pairs doesn't go through the table in any particular order while ipairs goes in order[/QUOTE]
ipairs doesn't work on non-numeric keys
[QUOTE=Kogitsune;47985342]ipairs doesn't work on non-numeric keys[/QUOTE]
Yeah I should've read the code a bit more, I just assumed he was trying to use the doors table within each of these subtables or whatever which had numeric indices
[QUOTE=Kogitsune;47985299]You can't really sort a table with non-numeric keys.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/SortedPairsByMemberValue]Global.SortedPairsByMemberValue[/url]
[code]for k, v in SortedPairsByMemberValue( houses_table, "id" ) do
...
end[/code]
This might work.
If not, you're going to have to remove the string keys and just let them be numeric instead.[/QUOTE]
Oh hey, thanks for this, this works, I thought you could only used 'in pairs' I didnt know there were more of these.
Sorry, you need to Log In to post a reply to this thread.