Soandso2
Well-known member
- Joined
- Mar 13, 2023
- RedCents
- 937¢
When you kill a mob and get regular exp, the game tells you in the "you gain experience" emote exactly how much exp you got. But when you get AA experience, it just says "you gain experience", so I wanted to make a little calculation telling me exactly how much AA experience you got. This is a bit tricky, since it is quite possibe to get several hundred percent exp. Killing a mob in the later expansions of the game can, with exp bonus, seasonal bonuses etc can give 3 AAs for a kill.
This is how I solved it:
[CODE lang="Lua" title="Calculating AA Experience" highlight="4"]local function aaExperience()
local newAAExp = tonumber(me.AAPointsTotal().."."..me.AAExp())
local aaExpReceived = string.format("%.3f", (newAAExp - currentAAExp)*100)
--print (newAAExp.."-"..currentAAExp)
local expleft = string.format("%.3f", (100000-me.AAExp())/1000)
currentAAExp = newAAExp
printf("\atExperience:\ax: \ay%s%%\ax, just \ay%s%%\ax to go! Total: \at%s AAs\ax",aaExpReceived,expleft,me.AAPoints())
end[/CODE]
Now, this works 99% of the time, but sometimes I see strange behaviour, where the calculation gives negative experience, or too much.
Finally I grew weary of seeing incorrect values from time to time, so I added line 4 for debugging, and soon enough I saw this:
3945.9004999999-3944,4904399999
and the message that I got 141% experience.
I found this to be strange and looked at my AA window, where it said that I had 9 (nine) something percent of an AA, not 90% as the above states.
I realise that the code is flawed also because if I have less than 10% AA exp, I need to figure out how to add a starting 0 (since the above ought to be 3945.09004, not 3945.90049 or 3945.9004999999)
But the major problems seems to be that something happens that changes the AA exp as a raw number out of 10,000 (10,000=100%) to a ten digit value, regardless of how much AA exp I have. Why is this? When testing this in an online Lua sandbox, like so:
it does not happen.
This is how I solved it:
[CODE lang="Lua" title="Calculating AA Experience" highlight="4"]local function aaExperience()
local newAAExp = tonumber(me.AAPointsTotal().."."..me.AAExp())
local aaExpReceived = string.format("%.3f", (newAAExp - currentAAExp)*100)
--print (newAAExp.."-"..currentAAExp)
local expleft = string.format("%.3f", (100000-me.AAExp())/1000)
currentAAExp = newAAExp
printf("\atExperience:\ax: \ay%s%%\ax, just \ay%s%%\ax to go! Total: \at%s AAs\ax",aaExpReceived,expleft,me.AAPoints())
end[/CODE]
Now, this works 99% of the time, but sometimes I see strange behaviour, where the calculation gives negative experience, or too much.
Finally I grew weary of seeing incorrect values from time to time, so I added line 4 for debugging, and soon enough I saw this:
3945.9004999999-3944,4904399999
and the message that I got 141% experience.
I found this to be strange and looked at my AA window, where it said that I had 9 (nine) something percent of an AA, not 90% as the above states.
I realise that the code is flawed also because if I have less than 10% AA exp, I need to figure out how to add a starting 0 (since the above ought to be 3945.09004, not 3945.90049 or 3945.9004999999)
But the major problems seems to be that something happens that changes the AA exp as a raw number out of 10,000 (10,000=100%) to a ten digit value, regardless of how much AA exp I have. Why is this? When testing this in an online Lua sandbox, like so:
Lua:
local a = 55
local b = 2998
local str = tonumber(a.."."..b)
print (str)
it does not happen.
Last edited:

