Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Divinity

New Coder
hello peeps, sorry for the dumb question :p, 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)
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
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
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 in other words, where i sort the 3rd column (points) from highest number to lowest (line 9), i want to sort 1st and 2nd columns (id and deaths) from highest to low, but instead, both must be based on the POINTS array
 
Back
Top Bottom