Sorting a table in lua
Hi, i am trying to figure how to sort a table with multiple entries
Here is my problem. I have something like that Code:
tArray["name1"] = { param1 = 10, params2 = 20, param3 = 50} so i tried somthing like that Code:
function sortParam1(a,b) is everyone know a way to do this? |
|
Uhm, I don't know if table.sort works for tables; I think it only works for arrays (tables with numeric keys in order, 1...n). Don't take my word on it though.
The other thing is, in your function, it says "a[1]<b[1]", but what is a[1]? Shouldn't it be a.param1? |
Quote:
but none of them is an answer to my question (they are all related to array with a single params), and this is why I am asking here. Quote:
this is tricking me ;) i know how to do that in delphi or c++ but not in lua... |
There's no way to do that, simply. Your table isn't even sorted by the keys, not to mention the value of the param1 attribute.
But, you can do something else. Code:
tArray={} |
thank you SinusPi, it works like a charm ^^
|
Quote:
|
All times are GMT -6. The time now is 07:37 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI