hey, I have never made this before, but I got a question.
How can I know from these values which is higher?
local Values = {1,2,3,20,0}
for i,v in pairs(Values) do
-- hm?
end
hey, I have never made this before, but I got a question.
How can I know from these values which is higher?
local Values = {1,2,3,20,0}
for i,v in pairs(Values) do
-- hm?
end
Use math.max:
local highest = math.max(table.unpack(Values))
print(highest) -- 20
Be aware that table.unpack errors with array sizes of 8000 or higher, so if your table is really huge then you would have to use the normal iterative method:
local min, max = Values[1], Values[1]
for _, x in ipairs(Values) do
min = math.min(min, x)
max = math.max(max, x)
end
print("min: "..min.."\nmax: "..max)
Or better yet compute the max and min as you initially add values to the table to avoid the need to iterate twice. (Assuming the table is filled by iteration as well.)