EXP Bar needs to scale to fit GUI

Hi guys!

First time here so firstly hi all!

I’ve ran into an issue and hoping somebody can help. Currently I have an EXP bar setup and working when I gain levels, however the area I am trying to have this fill when 100% is 557 Pixels wide.

I have the EXP Bar image scaling on X to match the GlobalVariable(EXP)

Currently this reaches 100 to gain a level which means my EXP bar only gets to 100 before resetting. How else would I be best off doing this and in a way that when my next level required for example 130 EXP this does not break ? I’m likely doing this a really bad way but I’m still learning and have been stuck on this all day!

Hi! If I understand well you want for each level, to have a certain value of EXP needed?

If Variable (EXP) >= level[VariableString(currentlevelnum)] [“EXPneeded”]

For each level you have already before set the EXP needed. Playing the game, program record the current level num and so can adapt directly the expneeded for this specific level.

I want to be able to increase the level requirements for each level such as level 1 required 100 exp, level 2 required 130 exp and so on, but to be able to have the exp bar cover the GUI EXP bar from 0 pixels to 557 pixels from 0% EXP to 100% EXP. Hopefully this makes sense.

Currently with my current code when EXP is at 100% The exp bar is 100 pixels long but need this to be 557.

I could alter the GUI to fix this however if level 2 required 130 EXP then when I am at 100% EXP the bar will be 130 pixels long.

Then you have to convert your actual EXP required, let’s call expR, into the visual EXP, let’s call it expV. Keeping the proportion.
You have to express expR over a maximum Exp

expR/maxExp = expV/557

So expV= 557 * expR/maxExp

Does it make sense?

I’ll try this in a bit and hopefully it works Thanks for the help!

1 Like

One thing to call out: Remember that “Scale” Works off the concept of multiplication, it is not a width length, but a “Factor of width’s length”.

So if you set the scale to 2x, it’ll be 2x the normal length, 0.5 will be 1/2 the normal length, etc.

If your EXP bar’s width is normally 100 pixels wide, you don’t have to do anything in the math related to 100 or 557. Custom width set in the scene editor will be overridden by the Scale event, too. (e.g. setting your exp bar width to 557 in the scene editor, then using events to set the scale to 1x, will reset the exp bar width to 100).

This means you either need to:
Edit your exp bar graphic/sprite asset to be 557 wide. Then you can use the Width Scale event and just set it to CurrentExpVariable/MaxExpVariable
or
Use the Width event, instead of the Width Scale event. Then you would use (CurrentExpVariable/MaxExpVariable) * 557.

1 Like

Thank you I’ll try that now, sounds like it should work but my only issue would be how do I then change the requirements for each level without ruining the EXP bar?

So if my requirements for level 2 is 100 then level 3 is 150 will that not then break the XP bar?

There’s lots of different ways to do that, but the easiest would be to ensure you’re storing a variable of “MaxExp”

When you level up, you should update that variable to be something like “EXPMultiplier*CurrentLevel”, or whatever math you want.

So if you want to say “level 1 is 100 xp, level 2 is 200 exp, etc”, you’d just set that variable to CurrentLevel*100 as part of your levelup process.

If you were instead wanting an exp curve, where it’s more like “Level 1 is 100, Level 2 is 150, Level 3 is 225” you’d update that variable with MaxExp*1.5 (Meaning you’d update the variable with itself * 1.5)

Then you’re just using the variable as part of the equation mentioned above.

Ahhh that makes sense! You are amazing, I’ll try these changes now! Thanks so much!

This all works perfectly Thank you very much for all your help! Sorry to be a pain though but 1 more question I’m now trying to figure out!

To trigger levels ups I have a condition that
The global variable of EXP is greater than or equals to the global variable of MaxEXP then it triggers the update of the global variable of Level to add 1.

I then have the variable of MaxEXP * 1.5 as you suggested above which works perfectly, however the problem I am now having is how do I maintain the carried over EXP through levels?

So if I require 100 EXP to level up and I gain 200, I should carry over 100 and be 100/150 if that makes sense?

Initially I set the trigger on level up to change the global value of EXP to 0 as this reset everything correctly but realised this didn’t work for carrying EXP over.

So can you program this? :
When reaching the next level, the EXP is not set to 0, but to “minus the previous level EXPrequired”.
So that you take off the required EXP from the EXP.

I tried that originally, but Im not sure why this isnt working.

Could it be because I have only 2 variables EXP and MaxEXP, as suggested above I’m now triggering MaxEXP*1.5 on level up ?

Or have I just completely ballsed up! Sorry I’m still a complete novice at this!

Hi, here is the detail of what I would do.

I write it my way, but you can mix it with Silver-Streak advices.

He said you can use a multiplier to change the exprequired, but I guess it works only if you want the exprequired depending in a mathematic way on the current level. (am I right Silver-Streak?)

Here I wrote another way where you would enter the different exprequired as game datas.

I didnt use the Width Scale event cause I don’t know it well, but you can easily replace in my example in order to use the Width Scale event

Game datas to enter once at the beginning:

exprequired.1 set to 100

exprequired.2 set to 150

exprequired.3 set to 400

exprequired.4 set to 250

… and so on

trigger once , when game starts :

currentlevel set to 1

currentEXP set to 0

Constantly (every frame) :

``````      → current EXP : substract exprequired[VariableString(currentlevel)]