I am working on a system that tracks the player’s place on the course. However, I am trying to figure out how to find the place of the player based on the data in the table. There are 12 entries in the table, ranging from 0 to 1. If the player is closest to 1, they are in first, if they are closest to 0, they are in last, and everything in between. I know I could manually compare every value with a bunch of if statements but I am sure there is a simpler way.
Just use table.sort, which in this case returns the table ordered from largest to smallest
table.sort(someTable,
function(a, b)
return a > b
end)
for index, value in pairs(someTable) do
print('player is positioned at ' ..index.. ' with a value of ' ..value)
end
So my table is structured like this, how would I use 1[2],2[2], etc. as the value to sort by?
https://gyazo.com/10e248a3c3d64171f523e937689dac1c
Nevermind, just had to add [2] to your solution when sorting the table.