Unlucky-Life / ankimon

Ankimon is a Anki Addon to Gamify your learning experience
Other
41 stars 5 forks source link

XP Bar after Level Up 0 #37

Closed nurkittel closed 3 months ago

nurkittel commented 4 months ago

Hi,

I don't know if it's supposed to be like that but every time my Pokemon reached a new level my XP-Bar was 0 and the EXP from the previous fight did not transfer to the new level. See screenshots.

Screenshot 2024-03-24 at 12 29 49 Screenshot 2024-03-24 at 12 31 39
Unlucky-Life commented 4 months ago

Yes this is correct. Basically => If your pokemon gets enough XP - more then needed for the next lvl => it reaches the next level and xp is set to 0.

I may need to re-do the logic in the future and correctly calculate the xp.

omfgroflmfaol commented 3 months ago

not sure if you fixed it already and just haven't put it into the change notes for 1.27 but I looked at the function save_main_pokemon_progress and the issue lies with the line mainpokemon_xp = 0. It needs to be changed to:

mainpokemon_xp = int(mainpokemon_xp) - int(experience)

With just this change, you would only level up once per fight, even if you have enough exp to level up more than once. This should occur rather seldomly, but it can also be easily fixed by changing the levelup event listener (if int(experience) < int(mainpokemon_xp) and mainpokemon_level != 100) to a while loop (the corresponding else can be left as is):

while int(experience) < int(mainpokemon_xp) and mainpokemon_level != 100 (...) else msg = "" msg += f"Your {mainpokemon_name} has gained {exp} XP.\n {experience} exp is needed for next level \n Your pokemon currently has {mainpokemon_xp}" (...)

Tested it and it works 👍

Note that the part within else is only executed when the while loop terminates naturally (by its condition becoming false), but not if you at some point decided to add a break command somewhere in the while loop.