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
haiku
Wanderer


Joined: 19 Nov 2004
Posts: 70

PostPosted: Sat Aug 11, 2007 6:18 pm   

question about #math/#VAR
 
This wasn't working for me, so I started doing some debugging.
Here's the trigger.
#VAR xpToLevel %1
#VAR tempXpValue (@xpIntoLevel + @xpToLevel)
#VAR PercentThroughLevel (@xpIntoLevel / @tempXpValue)
#SHOW xpIntoLevel: @xpIntoLevel
#SHOW xpToLevel: @xpToLevel
#SHOW tempXpValue: @tempXpValue
#SHOW PercentThroughLevel: @PercentThroughLevel

Here's the output:
You have acquired 167433680 experience points so far this level.
You need 39724719 experience points to gain level 72.

xpIntoLevel: 167433680
xpToLevel: 39724719
tempXpValue: 207158399
PercentThroughLevel: 0

Is cMud unable to do math on numbers this large? I've tried them all Integers, floats, autotypes... it evaluates to .80, so i thought I should try
#VAR PercentThroughLevel ((@xpIntoLevel / @tempXpValue)*100), but that still evaluated to 0.
I tried
#VAR PercentThroughLevel ((@xpIntoLevel *100 ) / @tempXpValue), but that evaluated to -2

Is there a reliable bigDecimal type variable?
Reply with quote
Zhiroc
Adept


Joined: 04 Feb 2005
Posts: 246

PostPosted: Sat Aug 11, 2007 6:32 pm   
 
Do:

#VAR PercentThroughLevel (@xpIntoLevel * 1.0 / @tempXpValue)

to convert the calculation into floating point.
Reply with quote
haiku
Wanderer


Joined: 19 Nov 2004
Posts: 70

PostPosted: Sat Aug 11, 2007 6:35 pm   
 
thanks, that worked!
Reply with quote
haiku
Wanderer


Joined: 19 Nov 2004
Posts: 70

PostPosted: Sat Aug 11, 2007 6:46 pm   
 
ok, next question... how do I truncate it so that I'm only seeing 2 places after the decimal point?
Reply with quote
haiku
Wanderer


Joined: 19 Nov 2004
Posts: 70

PostPosted: Sat Aug 11, 2007 6:53 pm   
 
or better yet, how do i cast it back into an integer?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Aug 11, 2007 7:01 pm   
 
To truncate: %int
To round: %round
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Sat Aug 11, 2007 7:52 pm   
 
Also there is the %format function.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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