Map (table/array) sorting
Posted: Sun Aug 01, 2021 12:12 pm
So I'm trying to get a list of key=value sorted by order of decreasing value, and I can't seem to find out how to do that with the available functions from iterators.lua.
Keep in mind that I'm really not an expert in Lua, as I barely understand its syntax. So I've adopted the spairs function found here (renamed as "zpairs" so as to avoid interfering with existing code that calls upon spairs).
So when I have
it works.
But if I try to use rpairs instead, it complains about an "attempt to compare two nil values".
Keep in mind that I'm really not an expert in Lua, as I barely understand its syntax. So I've adopted the spairs function found here (renamed as "zpairs" so as to avoid interfering with existing code that calls upon spairs).
So when I have
Code: Select all
for race, p in zpairs(empire_pop, function(t,a,b) return t[b] < t[a] end)
it works.
But if I try to use rpairs instead, it complains about an "attempt to compare two nil values".