Page 1 of 1

Divide By Zero

Posted: Wed Aug 18, 2004 4:11 pm
by Aarrow
Someone posted the code for a mana regen timer sometime before (Tells you how long before you are FM). I added it to my UI, but when I play a character without mana I get a Divide by Zero in Calculation error... so I added an if statement around it
Without If:

Code: Select all

${If[${Math.Calc[${Me.CurrentMana}/${Me.MaxMana}]}==1,"",${Int[${Math.Calc[(${Me.MaxMana}-${Me.CurrentMana})/${If[${Me.ManaRegen}>0,${Me.ManaRegen},1]}/10]}]}:${If[${Int[${Math.Calc[(${Me.MaxMana}-${Me.CurrentMana})/${If[${Me.ManaRegen}>0,${Me.ManaRegen},1]}%10*6]}]}>9,${Int[${Math.Calc[(${Me.MaxMana}-${Me.CurrentMana})/${If[${Me.ManaRegen}>0,${Me.ManaRegen},1]}%10*6]}]},0${Int[${Math.Calc[(${Me.MaxMana}-${Me.CurrentMana})/${If[${Me.ManaRegen}>0,${Me.ManaRegen},1]}%10*6]}]} -- ]}]}${Me.CurrentMana}/${Me.MaxMana}:${Me.ManaRegen}
With If:

Code: Select all

${If[${Me.MaxMana}==0,"",${If[${Math.Calc[${Me.CurrentMana}/${Me.MaxMana}]}==1,"",${Int[${Math.Calc[(${Me.MaxMana}-${Me.CurrentMana})/${If[${Me.ManaRegen}>0,${Me.ManaRegen},1]}/10]}]}:${If[${Int[${Math.Calc[(${Me.MaxMana}-${Me.CurrentMana})/${If[${Me.ManaRegen}>0,${Me.ManaRegen},1]}%10*6]}]}>9,${Int[${Math.Calc[(${Me.MaxMana}-${Me.CurrentMana})/${If[${Me.ManaRegen}>0,${Me.ManaRegen},1]}%10*6]}]},0${Int[${Math.Calc[(${Me.MaxMana}-${Me.CurrentMana})/${If[${Me.ManaRegen}>0,${Me.ManaRegen},1]}%10*6]}]} -- ]}]}${Me.CurrentMana}/${Me.MaxMana}:${Me.ManaRegen}]}
When I use the If statement, it dissapears from the UI, but I still get a Divide by Zero error. Is there an error in my code (I am new at this) or does MQ just do the equations anyway (Seems pretty inefficient if it does)?

Posted: Wed Aug 18, 2004 4:25 pm
by aChallenged1
Yes, the error is in your code.

There is a post on this somewhere here.

As I recall it has something to do with divide by .99999999 or some such.
I'd tell you more if I knew WTF I was doing, but I don't.

Posted: Wed Aug 18, 2004 4:26 pm
by Night Hawk
Lax wrote:The issue at hand is the divide by zero error, which I tried to explain in the announcements how to correctly solve ;)

Also, you can use Math.Calc.Int instead of ${Int}
e.g.:
${Math.Calc[1234.5678].Int} == 1235 (i think it rounds anyway)

Best solution:

Code: Select all

${If[${Me.Gem[1].ID},${Math.Calc[${Me.CurrentMana}/${If[${Me.Gem[1].Mana},${Me.Gem[1].Mana},9999999999]}].Int},]}
The main difference here is the inside check is if CurrentMana. Not all spells have mana (e.g. bard songs)

The issue at hand here for "Divide by zero" is that the calculation is always executed, no matter what. The parser has no idea there's an "if" there that you would want to stop part from being parsed. The only way you can make it realize there's an if, is if the if is INSIDE the calculation.