hello peeps, sorry for the dumb question 😛, i dont really program, i just do LUA modding for a game as a hobby
so, i am creating this scores table (imgui) with 3 columns, where in the first column i have 8 players IDs from blue to orange
then i have players number of Deaths
and a third column for player total score
the problem is sorting (i want to "link" each player color to their deaths and score. and want to display it from top to bottom, depending on who has highest score
(so lowest score is at bottom, etc)
I made a system of 3 arrays, that keep changing as game goes (except the colors of course)
now, at the actual scores table(imgui):
[CODE title="table sorting" highlight="8,9"]for pn=0,MAX_NUM_REAL_PLAYERS-1,1 do
imgui.TextUnformatted(PlayerNames[pn])
-- (future code to add)
imgui.NextColumn()
imgui.TextUnformatted(tostring(Deaths[pn]))
-- (future code to add)
imgui.NextColumn()
imgui.TextUnformatted(tostring(Points[pn]))
table.sort(Points, function(a,b) return a>b end)
imgui.NextColumn()
end[/CODE]
the highlighted part shows that i successfully sort the 3rd column (scores) from highest to lowest.
my objective here is also adding a table.sort function to the other 2 columns (ID and Deaths), where they get sorted based on the Scores array! (also from highest to lowest, so that all 3 columns are aligned: for each player, showing that player's deaths and points)
what would be a function to place in those 2 table.sort to reach that goal?
thanks!
ps.: feel free to look at an example of what i have
in the example, yellow player has 1 death and 5000 points, but unfortunately only the points column is right (so it's not really aligned, meaning it's displaying wrong stats)
in this case, "yellow" and "1" should be on top, aligned with 5000
so, i am creating this scores table (imgui) with 3 columns, where in the first column i have 8 players IDs from blue to orange
then i have players number of Deaths
and a third column for player total score
the problem is sorting (i want to "link" each player color to their deaths and score. and want to display it from top to bottom, depending on who has highest score
(so lowest score is at bottom, etc)
I made a system of 3 arrays, that keep changing as game goes (except the colors of course)
local PlayerNames = { "Blue", "Red", "Yellow", "Green", "Cyan", "Magenta", "Black", "Orange" }
local Deaths = { DeathsB, DeathsR, DeathsY, DeathsG, DeathsC, DeathsM, DeathsBL, DeathsO}
local Score = { scoreB, scoreR, scoreY, scoreG, scoreC, scoreM, scoreBL, scoreO }
now, at the actual scores table(imgui):
[CODE title="table sorting" highlight="8,9"]for pn=0,MAX_NUM_REAL_PLAYERS-1,1 do
imgui.TextUnformatted(PlayerNames[pn])
-- (future code to add)
imgui.NextColumn()
imgui.TextUnformatted(tostring(Deaths[pn]))
-- (future code to add)
imgui.NextColumn()
imgui.TextUnformatted(tostring(Points[pn]))
table.sort(Points, function(a,b) return a>b end)
imgui.NextColumn()
end[/CODE]
the highlighted part shows that i successfully sort the 3rd column (scores) from highest to lowest.
my objective here is also adding a table.sort function to the other 2 columns (ID and Deaths), where they get sorted based on the Scores array! (also from highest to lowest, so that all 3 columns are aligned: for each player, showing that player's deaths and points)
what would be a function to place in those 2 table.sort to reach that goal?
thanks!
ps.: feel free to look at an example of what i have
in the example, yellow player has 1 death and 5000 points, but unfortunately only the points column is right (so it's not really aligned, meaning it's displaying wrong stats)
in this case, "yellow" and "1" should be on top, aligned with 5000