i have a table like this
local levs = {}
local maxlev = 50
local loops = maxlev
local level = 1
local xp = 5
while loops > 0 do
loops = loops - 1
levs[level] = xp
xp = math.floor(xp + (xp / 2))
level = level + 1
end
this makes a table like
[1] = 5
[2] = 7
[3] = 10
[4] = 15
[5] = 23
and so on up to 50 im now needing to compare a value to the table and find a key that matches it for example if the input is 9 it ill read the table and find the last key that has a value less than 9 so in this case they key of 7 so it would return 2 and if the input was 16 it would return 4
i currently have this
_G.XPCheck = function(XP)
local keycheck = 1
if levs[keycheck] < XP then
keycheck = keycheck + 1
else
return keycheck - 1
end
end
is there a more propper way of doing this?

4 comments
I think so. I am answering your question
How would you do this?
almost done
Why are you setting numerical indexes for your dictionary? This could be hazardous in some cases and in your case its useless since you're defining in chronological order.