# Experience System for multiple Skills

Is there a simple was to compare a float (skill exp on char) to a data table that has a float (skill exp) and an int (skill lvl) and set the value of an int (skill lvl on char) depending on where on the data table the float is = to? Sorry if this doesn’t make sense…

Basically a system that says okay, you have 1200 experience points so this is what level you should be.

My data table right now has two columns, a Skill Lvl struct and a Skill Exp struct. My thought was compare my float to all the floats in the table to find the row it’s between, and set my int to the int from that same row?.. but can’t figure out how to do so.

Any help would be awesome!
Matt

You can use structs for that and an array of float. One struct is from your character info, that contains its lv and xp. The array has, in each index, the current exp to reach the lv (index + 1).

For ex:
Character Struct
Lv 2
Exp 200

Array ExpPerLv:
0: 0
1: 100
2: 200
3: 300

Each index must be read as the LV and the required XP as the value. The index ‘0’ is the lv 1, and it needs ‘0’ xp to advance to it. The index ‘1’ is the lv 2, and it needs 100 xp to advance to… and so on.

Okay, I think I understand! LV is line value I’m assuming…? I’ve never had to get the LV before but I’m sure I can find how to get it. But how would I do the float comparison? Do a find on the float array?

if you don’t want to show the player how much more exp they need to lv, you can use a float curve, with the exp on the x (horizontal) and lv. on the y (vertical) and just floor whatever value you get at that exp. Makes it really easy when balancing the game, cause then you can just move some points around instead of having to retype every value to keep the leveling curve good

Thank you, I got this method to work just fine!

This is actually what I was looking for! Thank you for this!

Could I not create another float curve with lvl on x and exp on y to calculate remaining exp? That seems like it may work??

Haha, “lv” was intended to mean Level
The line value you are assimilating is actually the index inside the array.

I mean, I don’t see why it wouldn’t work, but then you’d have to make sure that they match each other exactly, and if you’re using curves instead of straight lines, it might be a little hard to do. But if each skill only has like 5 levels then it shouldn’t be too much of a problem.

Is it best to hard code values to make an experience table or is there a better way to do this?

This is what you need to see.

I mean, this might seem like a stupid solution, but if you really want to use the curve to do this, you could add some code like this

``````

int32 maxLv;
UCurveFloat* expCurve;
// key == lv, value = exp
TMap<int32, int32> lvExp;

public void Initialize() {
int32 exp = 1;
while (true) {
int32 lv = expCurve->GetFloatValue(exp);
if (lvExp.Contains(lv) == false) {
if (lv == maxLv) break;
}
exp++;
}
}

public int32 NextLvExp(int32 currentExp) {
int32 currentLv = GetFloatValue(currentExp);
if (currentLv == maxLv) return 0;
return lvExp[expCurve->GetFloatValue(currentExp) + 1];
}

public int32 ExpToNextLevel(int32 currentExp) {
return NextLvExp(currentExp) - currentExp;
}

``````

It will might make starting up a lot longer if you have a lot of skills and they require a lot of exp, but it shouldn’t affect in game performance too much i think.

This is just off the top of my head btw, it might not actually work the way I’m thinking it will work

1 Like