• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[LUA] Creating an array, and comparing values to return the higher.

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,766
Solutions
1
Reaction score
225
Location
Chile, Santiago
Hi there... Well I need something that compares the values of an array and return the higher value of the array and tell me the position, for example:

Lua:
contador_g = {}
....
contador_g[guildid]++
....

I don't know if the "++" works on lua... Anyways I need to take that array, compare al values and return the value and the position (in this case, guildid).
 
something like this?
Lua:
function getHighestValue(array)
local x = nil
local y = nil
for i = 1, #array do
    if not x or (array[i]  > x) then
        x = array[i]
        y = i
    end
end
    return x, y
end

and use it like this:
Lua:
local value, position = getHighestValue(array)
and value will give the highest value in the array and position will give what position it is in the array.

Its not tested and there is no check to make sure array is actually an array but Im sure it will work the way you described.
 
Back
Top