23.06.2020, 22:13
(23.06.2020, 06:28)admin Wrote: You can find the maximum value like this. If two items have the same on_time then the one that appears first in the table will be returned.Many Thanks, i have it working
Code:max_index = 0 max_time = 0 for index, item in ipairs(t) do if item.on_time > max_time then max_index = index max_time = item.on_time end end max_item = t[ max_index ] if max_item then log(max_item) end
Or you can sort the table using custom comparison function. In this case the order of elements in not defined if on_time is the same. t[1] will contain the element with maximum on_time value.
Code:table.sort(t, function(a, b) return a.on_time > b.on_time end) log(t)