Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
cxs410
Beginner


Joined: 04 Oct 2005
Posts: 20

PostPosted: Tue Oct 18, 2005 1:35 am   

What am I doing wrong..
 
I want to display some info in my status window..
for some reason these lines calculate to 0


#MATH hp_percent {(@cur_hp/@max_hp)*100}
#MATH ave_exp {@experienc/@kills}

any idea what i'm doing wrong here?
Reply with quote
ChrisD
Beginner


Joined: 18 Oct 2000
Posts: 18

PostPosted: Tue Oct 18, 2005 2:33 am   
 
#MATH hp_percent {(@cur_hp/@max_hp)*100}
#MATH ave_exp {@experienc/@kills}


I suspect in your first line the () is getting evaluated to 0.xx and truncated down to 0. Try this instead:

#MATH hp_percent {(@cur_hp*100)/@max_hp}

For the second, check that you have some value in @experience (with an e). Try:

#ECHO Current value of experience is: @experience
#ECHO Current value of kills is: @kills
#ECHO Average experience per kill: @ave_exp

Paste us the results.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Oct 18, 2005 2:35 am   
 
mathematical operators in ZMud use integer math, which means only the numbers to the left of the decimal point are shown. Given that percentages are always a decimal number between 0 and 1, that means the integer portion of said number will always equal 0.

It's been a little while since I used percentages, so lemme see if I can remember this:

(A * 100) / B?

A = 5, B = 10

(5 * 100) / 10 = 500 / 10 = 50. Yep, that's it. Very Happy

EDIT: Oh, there's also a function to force zmud to use floating-point math, too. %float() around just one number will keep the decimal for you (it doesn't really apply to your problem, just thought I'd toss it out since we were on the subject.)
_________________
EDIT: I didn't like my old signature
Reply with quote
cxs410
Beginner


Joined: 04 Oct 2005
Posts: 20

PostPosted: Tue Oct 18, 2005 5:34 am   
 
#MATH hp_percent {((cur_hp*100)/max_hp)/10)}
#MATH ave_exp {@experience/@kills}

those two work, thanks for helping me with the %'s and as for the second one, I'm lame and had the wrong spelling and didn't realize until i read the posts..
Thanks again!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net