Posts ID:159887 Favorites Creations
 ID:159887   Dec 28 2008, 11:13 pm Ha, threw you off with the topic, anyways I'm trying to figure out how to, instead of getting the error of dividing by 0, how do I make it replace the bug and just say something simple like, Division by 0 attempted. Instead of 5-6 long lines of red evil on the eyes text? Is it possible to actually go in and change byond built in processes? I've got it on things like Repop, but I'm unsure on how to do it for like if(3/0) how would you modify /0 to say instead Hey, you cant Divide by 0! (And I know this really isn't the place but I hate to bump old threads >.> no one has replied) id=679457
 #1 Dec 28 2008, 11:15 pm ... why the heck would you want to do that? It'll tell you that you are trying to divide by 0 and do nothing else anyways! If you want to avoid 0 division by having a higher divisble number, ex: 1, use max().
 #2 Dec 28 2008, 11:20 pm In response to GhostAnime (#1) GhostAnime wrote: ... why the heck would you want to do that? It'll tell you that you are trying to divide by 0 and do nothing else anyways! If you want to avoid 0 division by having a higher divisble number, ex: 1, use max(). yea, but when starting out in certain games the Stat() proc works, with the HP and Max being 0, it returns the Divide by zero error repeatedly and pretty quickly getting annoying until the suppression comes up, and then you wont be able to see any errors later in the game.
In response to Inuyashaisbest (#2)
if(maxhp > 0) stat(...

Though ideally you would have initial divisible stats defined as 1 rather then null or 0:
 ```mob/var hp = 0 maxhp = 1 // 0 = divisible error ```
In response to Inuyashaisbest (#2)
 ```proc percent(min,max,round=1) if(!min||!max)return 0 //You can make this return anything you want, but it'll return 0 instead of giving you an error. return round(min/max*100,round) ```

Threw this together in a few seconds, so it's probably nitty and gritty. An example of how to use it would be like so:

 ```mob var hp=25 max_hp=50 verb/test() world<

And for statpanels:
 ```mob Stat() stat("Hit Points:","[hp]/[max_hp] ([percent(hp,max_hp)]%)") ```

Edit: Forgot to close DM tags.
Edit 2: Added stat panel example.
Edit 3: Made percent() a little simpler, I think.

This should make it so you don't get a error whenever the statpanel updates, but rather it will return 0%. I hope this solves your problem though I don't think it does.