ID:168341
 
Well, when a mob is on the login screen, it's HP is 0, as well as max hp. In the stats menu, I have the formula to put the mob's hp as a %. Now, the problem is, when a mob logs on, dreamseeker needs to do [0 / 0] , but because it can't it gives a runtime error. When I put this in the login:

src.hp = 5
src.maxhp = 5


the error stops. But when someone loads his saved character the hp and max hp is 5, instead of the char's loaded stats.

I tryed calling the stat proc ONLY when the mob has loaded/created a char, but the technique I used was with a simple var and was kinda buggy. So, could anyone give me help on this? Quite annoying being flooded with runtime errors when you login.

runtime error: Undefined operation
proc name: Stat (/mob/Stat)
source file: mobs.dm,179
usr: Mysame (/mob)
src: Mysame (/mob)
call stack:
Mysame (/mob): Stat()
if(MyHP && MaxHP)

Remember, less than 1 returns a false value :)
In response to Ireus
Wha? That didn't make sense o.O (Altough, for me)
Just set them to 5 at the definition...

mob
var/HP = 5
etc...

Then, they'll work fine for the initial stat generation, and will be overwritten by your file loading...
In response to SuperSaiyanGokuX
How the hell didn't I think of that...

Thanks SuperSaiyanGokuX !!
In response to Mysame
The guy is trying to percent something, but gets zero division errors. Well checking if either value is 0 before doing the calculation is an easy way to avoid it... though there are better ways.
In response to Ireus
Ireus wrote:
The guy is trying to percent something, but gets zero division errors. Well checking if either value is 0 before doing the calculation is an easy way to avoid it... though there are better ways.

you'd just want to check if their max hp is zero. if their max is 100, and their current hp is zero, that's perfectly fine. that would show up as 0%, which is correct.

if their maxhp is zero, then you'd be dividing by zero which is what causes the error.

if(maxhp)
stat("HP","[round(hp / maxhp)]%")
In response to OneFishDown
True, but I was edging towards replacing the percetage with "Dead" ...but thats just me >.>
In response to Ireus
Ireus wrote:
if(MyHP && MaxHP)

Remember, less than 1 returns a false value :)

Technically only 0 is a false value; less than 1 means literally anything less than 1, and all those values are true except for 0.

Lummox JR
In response to Lummox JR
You kidding!? I thought 0 and negative numbers were considered False by DM?

...I hope Im correct... I know I wrote a proc about a week ago that relys on -num being false O.O
In response to Ireus
No, you're wrong. In DM, only three things are false: 0, null, and ""

That's one thing that makes BYOND difficult for beginners to learn. In many "beginner" lines, only #f (false) is false, and anything other than #f is true.
In response to PirateHead
I remember 0 null and an empty string...but now you mention it Ive seen -numbers passed as true before and it hasnt bothered me.. woe is my shakey brain.
In response to Ireus
Ireus wrote:
You kidding!? I thought 0 and negative numbers were considered False by DM?

Gads no. Only 0, an empty string, and null are false values in DM. No idea where you'd get the impression that negative values are false, because it holds in no programming language whatsoever, and this is also common knowledge.

Lummox JR
In response to Lummox JR
Gads no. Only 0, an empty string, and null are false values in DM. No idea where you'd get the impression that negative values are false, because it holds in no programming language whatsoever, and this is also common knowledge.

Not to mention that it is common in many languages for -1 to be the true value returned by operators and functions due to the fact that in twos complement notation -1 is stored as all bits being high.
In response to Theodis
Ah, confusion solved! I made a lil scripting language for an old vb game, and negative value would return false... though i remember having negative text strings somehow...

Think I'll leave the language writing to the experts :P