Here are some table functions which I think that they are really usefull.
example:
works same as above but returns the index of the highest value.
example:
If you have any kind of requests for table functions feel free to ask here, will try to add them then.
Kind regards, Evil Hero.
Lua:
table.getIndexOfLowest = function(table)
local lowest, r = table[#table], {}
for var = #table,1, -1 do
if table[var] == lowest then
table.insert(r,var)
lowest = table[var]
elseif table[var] < lowest then
for a = 1,#r do
table.remove(r, a)
end
table.insert(r, var)
lowest = table[var]
end
end
return r
end
Lua:
local t = {5,3,1,2,7}
if #table.getIndexOfLowest(t) > 1 then
for a = 1,#table.getIndexOfLowest(t) do
print(table.getIndexOfLowest(t)[a])
end
else
print(table.getIndexOfLowest(t)[1])
end
output-> 3
because in the table the index of 3 has the lowest value.
if we however have in a table 2 times the same value like this
local t = {5,3,1,2,7,1}
output-> 3
output-> 6
works same as above but returns the index of the highest value.
Lua:
table.getIndexOfHighest = function(table)
local highest, r = table[#table], {}
for var = #table,1, -1 do
if table[var] == highest then
table.insert(r,var)
highest = table[var]
elseif table[var] > highest then
for a = 1,#r do
table.remove(r, a)
end
table.insert(r, var)
highest = table[var]
end
end
return r
end
Lua:
table.shuffle = function(table)
local iterations = #table
for i = iterations, 2, -1 do
j = math.random(i)
table[i], table[j] = table[j], table[i]
end
end
example:
Lua:
local t = {nil,true,false,50,"hello"}
math.randomseed(os.time())
table.shuffle(t)
output-> {true,"hello",false,nil,50}
basicly it just randomize the index with it's according value to another index.
If you have any kind of requests for table functions feel free to ask here, will try to add them then.
Kind regards, Evil Hero.
Last edited: