# v19.1Error when levelling up to maximum level during Single Battles

This thread pertains to v19.1 of Pokémon Essentials.

#### Armin

##### 破壊の神
Member
An error is obtained when a Pokémon levels up to its maximum level during Single Battles, e.g. Lv.99 -> Lv.100. (Levelling up via a Rare Candy or Double/Triple battles are not affected.) I believe it has something to do with way the animation of the blue Exp bar filling up is processed/calculated.

Here is a fix I propose:

1) In the script section, PokeBattle_SceneElements, right under "def animateExp", add this line:

Ruby:
if @battler.level != Settings::MAXIMUM_LEVEL

Add an "end" at the end of the section, to get this:

Ruby:
def animateExp(oldExp,newExp,rangeExp)
if @battler.level != Settings::MAXIMUM_LEVEL
@currentExp     = oldExp
@endExp         = newExp
@rangeExp       = rangeExp
# NOTE: Filling the Exp bar from empty to full takes EXP_BAR_FILL_TIME
#       seconds no matter what. Filling half of it takes half as long, etc.
@expIncPerFrame = rangeExp/(EXP_BAR_FILL_TIME*Graphics.frame_rate)
@animatingExp   = true
pbSEPlay("Pkmn exp gain") if @showExp
end
end

2) Under def refreshExp, replace the line "w = ((w/2).round)*2" with the following:

Ruby:
if @battler.level == Settings::MAXIMUM_LEVEL
w = 0
else
w = ((w/2).round)*2
end

The section should look like this:
Ruby:
def refreshExp
return if !@showExp
w = exp_fraction * @expBarBitmap.width
# NOTE: The line below snaps the bar's width to the nearest 2 pixels, to
#       fit in with the rest of the graphics which are doubled in size.
if @battler.level == Settings::MAXIMUM_LEVEL
w = 0
else
w = ((w/2).round)*2
end
@expBar.src_rect.width = w
end

For games in v18.1, "Settings::MAXIMUM_LEVEL" will be replaced with "MAXIMUM_LEVEL". Hope this helps!