Say I have this 'thing': ( [1] What is the correct term for it?)
local Level = { {1, 0, 500}, {2, 500, 1000}, {3, 1000, 2000} }
I also have an IntValue
called Exp
:
local Exp = Player:WaitForChild("Exp")
[2] How would I 'scan' the table/dictionary/whatever to be able to get Level[?][1]
where the Integer is in the range Levels[?][2] < Exp < Levels[?][3]
(<-- That's the best way I know how to explain it)
E.g.
Exp = 560
The program would output
print("Level: "..--something) >>> Level: 2
Hmm, here's a version that would work, i'd go through each one and check if its in between and if so then there's your level
local Level = { {1, 0, 500}, {2, 500, 1000}, {3, 1000, 2000} } local Exp = 560 function FindLevel(exp) for _,v in pairs(Level) do if exp>=v[2] and exp<v[3] then return v[1] end end end print("Level: "..FindLevel(Exp))
The correct term for what you are assigning to Level
is a "table" (in this case, a "multi-dimensional table", "nested tables", or "table of tables").
There are a few other ways of representing your Level table:
Level[someLevel][1]
, but can instead do Level[someLevel].MinXP
Level = {500, 1000, 2000}
-- each number represents that maximum XP for that level. ex, Level[1] == 500, so if they have less than 500, they're at level 1.In either case, you'll want to use a for
loop to get the correct level. If you use option 3, the code would look like this:
local Level = {500, 1000, 2000} function LevelFromXP(xp) for i = 1, #Level do if xp < Level[i] then return i end end return #Level + 1 -- or whatever level you want them to have when they have more XP than the last entry in the Level table end