ID:263585
 
mob/Stat()
//
statpanel("Stats")
stat("Level","[src.Level] ([src.MaxExp/src.Exp]%)")


mob
var
Exp = 0
mob
var
MaxExp = 100


There are no errors but I get this when I run it:

Lanzo Kuryuu (/mob): Stat()
Lanzo Kuryuu (/mob): Stat()
runtime error: Division by zero
proc name: Stat (/mob/Stat)
usr: Lanzo Kuryuu (/mob)
src: Lanzo Kuryuu (/mob)
call stack:

OVER AND OVER AND OVER AND OVER AND OVER!

In my statpanel it only shows the stats that are before "Level". How can I fix this?


Division by zero: You are dividing 100 by 0. I dunno why, but it seems to give you a nasty little bug.

PLUS, the percentage calculation is wrong.
% = (Exp*100)/Max_Exp
(explanation)
Max_Exp = 100(%)
-------- ------
Exp = ? (%)
? = Exp * 100
---------
Max_Exp

Also ,at the beggining of your code, add <font color=green>#define DEBUG</font>. On the runtime error, with DEBUG on, DS will display in which line the code was ''wrong''.

Post an update soon ;)
stat("Level","[src.Level] ([src.Exp/src.MaxExp]%)")
In response to Gooseheaded
Gooseheaded wrote:
Division by zero: You are dividing 100 by 0. I dunno why, but it seems to give you a nasty little bug.

PLUS, the percentage calculation is wrong.
% = (Exp*100)/Max_Exp
(explanation)
> Max_Exp = 100(%)
> -------- ------
> Exp = ? (%)
>
> ? = Exp * 100
> ---------
> Max_Exp

Also ,at the beggining of your code, add <font color=green>#define DEBUG</font>. On the runtime error, with DEBUG on, DS will display in which line the code was ''wrong''.

Post an update soon ;)


because 0 goes in to N (any number) over 1.#INF times without using up the full value of 0. it's not a bug, it's math :P
Dividing 0 into a number is perfectly fine and gives 0 like we'd want it to. You are trying to pull out a percentage with the wrong formula. It should be (health/maxhealth)*100.
In response to Nodvick
But he just divided something. I don't think that should bug DM/DS...
In response to Gooseheaded
Gooseheaded wrote:
But he just divided something. I don't think that should bug DM/DS...

try dividing anything by 0 on a calculator. Same thing. Not possbile to divide something into no parts. Defies the actual act of divding. Which is why any form of calculator (including a computer) will give you an error that you cannot divide by 0
In response to Jik
Dividing by zero will not result in infinite btw.

3/0 = inf/1
0*inf=3*1
0 != 3

Conclusion: There is no infinite, just a point that's very close to it.



In response to Kazekage
Your whole problem is that you assume a number can be divided by zero, which it can't. It's an undefined operation.

And yes, there is infinty. There are entire areas of mathematics based purely on it's existence.
In response to Kazekage
Kazekage wrote:
Dividing by zero will not result in infinite btw.

3/0 = inf/1
0*inf=3*1
0 != 3

Conclusion: There is no infinite, just a point that's very close to it.

x/0 is undefined, not infinity. This is an important principle in Calculus.

1/infinity is equal to 0, though. It's not really equal to 0, it's just as close to zero as you can get (think 0.00000000~1), this makes it zero for use in math.

You can't use infinity in math like that. It's a concept, not a number.
In response to Nodvick
you forgot to multiply by 100 for the % :P

Also, I recommend the round() proc >_>