Need help

Yesterday I made this basic leveling up system and made it into a function so that I can call it whenever I need to add exp and it works great for what I need however I noticed an issue while testing if I added a large exp amount in one take that exceeds the max limit of the second level exp the system brakes it fills the first bar to the limit then adds all of the remaining to the second without taking into consideration the limit for example if I added 15000 and the limit is 2000 it fills the bar to the end and adds the remaining 13000 to the second I know that it has to do with the overflow exp node but I can’t figure out the right way to fix it

I can see why that would happen.

You can completely remove the Overflow EXP variable. Just set EXP to EXP - MaxEXP. There’s no reason to have it be 0 while calculating max- it isn’t used in those calculations.

To actually fix your issue, you just need to add a pin redirecting back to the start of the branch node after changing the max. Pseudo-recursion.

1 Like

Here is a suggestion to change a couple of things in your function:

Some notes:

  • As @rokenrock said, you do not need overflow variable.
  • The loop handles the logic to change level and update accordingly. It will skip to completed if conditions are never met.
  • Handle variables by references inside functions.
    SetByRef

For reference this is the function in the actor component to test:

Result:
LvlUp

Hope it helps.

1 Like

Hey, thanks for the help I appreciate it a lot however I can’t quite fully understand what you did could you maybe explain it in more detail please?

Sure.

Pass-by-Reference
  • First edit variables by reference: Allows the function to work 100% independent of the variables declared in the blueprints; meaning that if we change / delete any of there variables, the function won’t be affected. Using functions inputs (parameters) as Pass-by-Ref allows us to keep it that way since it passes the adress of the variable and not its value.
    image
    Notice Pass-by-Reference have a different pin then ‘regural’ varaibles:
    image
    Also notice reference variables have a different pin:
    image
    Inside functions you can use parameters as variables without having to drag from the Input node:
    VarByRef


Regarding the function: what I understand you are after is a way to add xp, level up, Increase 10% to reach next level. That is exactly what it does with the added loop that after increasing level, checks again if the difference from prev level is greater than the new level.

Pseudo:

InToNextLevel += InGained

WHILE InToNextLevel > InMaxLevel 
    InToNextLevel -= InMaxLevel 
    InMaxLevel *= 1.1 
    ++InCurrentLevel
END WHILE // Checks while loop condition again before continuing.

For every time InToNextLevel is greater than InMaxLevel, we execute while loop we get a value that is less. This way we can have any amount of XP added and levels will be skipped accordingly:

BigLvlUp

In detail:

The variables: InToNextLevel (ref) holds the current xp, InGained (ref) is added:

Compare the new xp to the current max level, if its higher that means we have enough to level up, BUT we don't know if we have enough to simply jump to next level or multiple levels so we check in a while loop until the condition is false (meaning the xp is less than needed for new level):

Assiming we have more xp than max, we subtract maxlevel to the xp so next loop we check if we have enough for next level:

Next we increase the xp needed to level up by X amount:

Finally we increment the level int:

image

If xp is less than max level, then we skip the loop and go straight to the return node:

Hope it makes sense.

thanks a lot! I really appreciate the help you guys are awesome

I’m sorry I’m a little bit new to the engine but I kinda try to make everything myself rather than copying 50 tutorials without actually understanding anything it usually works but not in the best way

anyway, thanks a lot for the help!

OK one last thing how can I link this to my progress bar it won’t work with my current setup

Personally, I have a value for my XP. Then the UI works out how to show that XP as levels. I use an algorithm to work out what level that equates to. So like Last level XP, x1.5 = next level. But I have that algorithm set up an array with the level marks So 1000XP, 1500xp 2250xp ect. Then I just have the UI go through the array to work out what index the current XP falls between. The I can subtract the level before it from the next level to reach to get my XP for the full level. Then the current XP over the previous level is the part for the percentage for the progress bar.

In the end, I have an array that has all the levels. The xp is just a variable. The UI then works out from the array and the variable, how to display it. You can jump 100 levels in an instant, and as long as the array goes up that high, then the UI will just calculate how to show it.

2 Likes

my god this is even more complicated :sweat_smile:

The key is to separate everything out into separate objects. Rather than have 1 single thing do everything at once. One thing like the Game Instance, Creates an Array of Level thresholds. The array is done. Why? Because if you want to alter the way the levels are reached, it’s easier than calculating all the levels yourself and putting every single value in all the way up to lvl 100. You just tell it to increse the amount to the next level by 1.5. And if you want to increase it, you just change 1.5 to 1.75.

One thing changes a variable called “Current XP” It just adds it onto the current amount.

The UI just finds what level the value equates to. If CurrentXP > LevelArray item, break. And CurrentLevel = the index +1.

Get a copy of that index and that’s the low end. Get a copy of the index +1 and you have the next level. NextLevel - PreviousLevel = FullLevelAmount. CurrentXP - PreviousLevel = LevelProgression. I think it’s LevelProgression / FullLevelAmount = ProgressBarPercent.

Splitting it all up makes each bit simple. And you can problem solve it WAY easier.