Divide By Zero

Need help running MacroQuest2? Ask your questions about how to get things to work on your computer.

Moderator: MacroQuest Developers

User avatar
Aarrow
a lesser mummy
a lesser mummy
Posts: 30
Joined: Thu Aug 12, 2004 2:38 pm

Divide By Zero

Post by Aarrow » Wed Aug 18, 2004 4:11 pm

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)?

User avatar
aChallenged1
a grimling bloodguard
a grimling bloodguard
Posts: 1804
Joined: Mon Jun 28, 2004 10:12 pm

Post by aChallenged1 » Wed Aug 18, 2004 4:25 pm

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.
Fuck writing MQ2 macros. Go with IS scripts; IS Rules!

User avatar
Night Hawk
a grimling bloodguard
a grimling bloodguard
Posts: 590
Joined: Fri Aug 13, 2004 4:56 pm

Post by Night Hawk » Wed Aug 18, 2004 4:26 pm

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.