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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
TiberSeptim
Beginner


Joined: 20 Jun 2006
Posts: 24

PostPosted: Mon Mar 12, 2012 8:00 pm   

2.37->3.34 some float math broke
 
The "nerve center" of my package is my prompt trigger. It basically looks for something along the lines of: %d(%d) %d(%d) %d(%d) to grab the max and current values for hitpoints, mana and moves respectively.

I then do things like #VAR hpp ( ( %1.0 / %2.0 ) * 100 ) to store my current hp as a percentage of total. This worked fine in 2.37 and now in 3.34 it returns 0 no matter what I seem to do...

What am I missing?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Mar 12, 2012 10:13 pm   
 
The problem is likely how you are attempting to cast %1 and %2. Use %float(%N) rather than %N.0.
_________________
EDIT: I didn't like my old signature
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4692
Location: Pensacola, FL, USA

PostPosted: Tue Mar 13, 2012 3:15 pm   
 
#VAR hpp ( ( %1 / %2) * 100.0 )
would work
_________________
Discord: Shalimarwildcat
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Mar 13, 2012 11:41 pm   
 
no, it wouldn't. Unless the MUD is sending floating-point numbers already (which is very doubtful), the division of %1 by %2 would operate under integer math--meaning that if %1 < %2 then (%1 / %2) = 0.
_________________
EDIT: I didn't like my old signature
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4692
Location: Pensacola, FL, USA

PostPosted: Wed Mar 14, 2012 11:31 am   
 
but its part of a larger equation that does include a floating point....
_________________
Discord: Shalimarwildcat
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Mar 14, 2012 3:13 pm   
 
That doesn't matter, Shalimar. Yes, the final result will be a floating point number, but the division will be integer division unless either the numerator or the denominator is a floating point number. However, the equation could have been rewritten so that it would use floating point division by making the numerator or denominator a floating point, e.g.:
#VAR hpp ( ( %1 * 100.0 ) / %2) )
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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