Division by zero for XP
Hi @all
I use for my XP display the following lines: Lua Code:
and Lua Code:
The last line gives rise to the error mentioned in the thread title. The funny thing here is that I use the same script on the live server and it works there. Also on the Beta server, the correct values are calculated and shown what you see on the screenshot below. The error also occurs only at login and at each subsequent reload it exists not even. My question now is ... Do I have a mistake, I do not see the forest for the trees or Blizzard has an error return values? Thanks in advance for all input. greetz liquid |
They've done this for the past few betas - I believe it's so they can optimize the default UI; cut out any instances of division-by-zero that are otherwise handled (likely less efficiently) by the live version's Lua parser. Division by zero is, after all, something most programmers code against, not for.
|
So then it would simply wait and see what is no satisfactory answer :(
|
Lua Code:
|
Thanks Torhal to solve the problem with this idea I did not come. I should just take a break :o
|
Shouldn't that be (maxXP == 0)?
|
Could be netter. I will test it :)
Thanks for all help! |
Quote:
Their decision to force Lua to throw division-by-zero errors was to make it act more like C. Quote:
|
I'm curious why you have the extra function and function call and aren't just doing this?
Lua Code:
|
Quote:
|
It happened, otherwise the error would've never been thrown. The code as-is can already handle if XP is zero, but not maxXP.
|
Quote:
|
@Seerah
You're right. The function is a relict from the old script within the UI I had only copied. @Torhal Thanks to you it works fine :) @SDPhantom with (maxXP == 0) the script throw a error if I want to display the value in a tooltip because of the nil-value. |
Quote:
If you need help with specific changes, you'll have to show your code. |
Quote:
Code:
local percXP = (maxXP == 0) and 0 or math.floor((XP / maxXP) * 100) If you post your entire code, we'll be able to help better and may catch problems that you might not see. |
Sorry for the late response.
The error occurs on line 89 if the character has no rested experience. Without (maxXP == 0) the script works as should. And the problem is not "nil" (my mistake in the interpretation) but it is a boolean instead of strings returned. With the expression the script throws the following error: Lua Code:
Thanks for all help, you guys are great :) Complete Script: Lua Code:
|
Do what SDPhantom says.
|
Quote:
Code:
if XP == 0 and maxXP == 0 then Code:
local XP, maxXP, restXP = UnitXP("player"), UnitXPMax("player"), GetXPExhaustion() |
Done it Phanx.
Thanks for all the input :) |
All times are GMT -6. The time now is 12:52 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI