# math help for exp bar

Get help using Construct 2

### » Mon Feb 09, 2015 8:55 pm

I have three variables to account for I'm having problem getting bar to always be the right size depending on the current exp value

the bar itself is 170 pixel wide / initial value set to 0
variable 1 bar.initialWidth = 0

the player
exp = 0

then 5 global values
lvl1 = 240
lvl2 - 480
ext..

I'm trying to have that bar grow with his exp and max out filling the bar to 170 pixels when the lvl1 exp needed is reached and lvl2 exp is reached ext...

i have tried something I used on an old game for health

(Self.InitialWidth + (Math_Boy.exp-Math_Boy.MaxExp)*(Self.InitialWidth/Math_Boy.maxExp))

but that didn't work granted I changed the way the MaxExp was working but even setting the player to hold both the MaxExp and the exp value didn't work in this case... can't figure out why?
You do not have the required permissions to view the files attached to this post.
Need Sprites For Your Next Project?
100% Vector Animated Sprites
B
8
S
2
Posts: 170
Reputation: 1,086

### » Mon Feb 09, 2015 10:27 pm

You should use Array, to contain data of levels scope.

Then, you need variable, to get data from array (CurrentLevel)

Formula of changing bar's (healthbar, manabar, expbar...) size is very simple:
Width of your bar / Value you want to reach * Current Value

So,

Then, if value of your CurrentExp is greater or equal to scope, you need to make a little check:

For example:
Array:
x1 = 240
x2 = 580

CurrentLevel = 1 (So the scope is 240)
CurrentExp = 260

It will:
- check if CurrentExp > Array.at(CurrentLevel) (260 > 240)
- set CurrentExp to CurrentExp - Attay.at(CurrentLevel) (260 - 240 = 20)

You will get level 2 and 20 exp with it

I hope I have explained completely enough
You do not have the required permissions to view the files attached to this post.
B
39
S
17
G
6
Posts: 238
Reputation: 8,045

### » Mon Feb 09, 2015 10:34 pm

wow thank you soo much that was very insightful
Need Sprites For Your Next Project?
100% Vector Animated Sprites
B
8
S
2
Posts: 170
Reputation: 1,086

### » Mon Feb 09, 2015 10:39 pm

oh i was too slow, anyway here is another solution with the dictionary
You do not have the required permissions to view the files attached to this post.
yeah, i really like to say that you should "Read this:"
B
16
S
8
Posts: 140
Reputation: 1,894