|
TiberSeptim Beginner
Joined: 20 Jun 2006 Posts: 24
|
Posted: 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? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Tue Mar 13, 2012 3:15 pm |
#VAR hpp ( ( %1 / %2) * 100.0 )
would work |
|
_________________ Discord: Shalimarwildcat |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Wed Mar 14, 2012 11:31 am |
but its part of a larger equation that does include a floating point....
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: 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) ) |
|
|
|
|
|