How to compare number values?

I’m trying to compare multiple number values with math.min in a system like this:

local value = {player,number}

how do I compare values like that, assuming the tables already have multiple values, and print out the player that was inserted to the value with the number?

maybe something like this?

function min(...)
	local Lowest = {nil, math.huge}
	for _, Table in ipairs(table.pack(...)) do
		if Table[2] < Lowest[2] then
			Lowest = Table
		end
	end
	return Lowest
end

local Lowest = min({"AAA", 5}, {"BBB", 3}, {"CCC", 8})
print(Lowest)

Code may look a bit confusing, so if you want an explanation of any part of it, let me know!

I don’t understand how it works, can you tell me please?

I imagine the main confusing part is ...?
... basically just contains any extra parameters in the function. It returns them as a tuple (Basically a list of the values).

To be able to loop through them, I change them all into a table, which I do using table.pack(...)
It just changes it from Value1, Value2, Value3 to {Value1, Value2, Value3}.

Does the rest of the code make enough sense, or do you need me to elaborate on another part of it?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.