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


Joined: 21 Jan 2005
Posts: 99
Location: Solvang, CA

PostPosted: Sun Apr 24, 2005 4:20 pm   

Oddity in math formula
 
I have a script that tracks my trains gained per level (it's variable, 2-5, with random "lucky bonuses" of 1-3 more, so max is 5+3, minimum is 2+0) on the MUD I play. The average generally ranges from 3.75 to 4.15.

When it's between 4.01 and 4.09 though, it displays as 4.1 to 4.9 (removes the 0 in front). I'm sure this is due to an error in my math formula, but am unsure what that error is. If anyone can spot the problem, it would be greatly appreciated :)

Code:
#VAR lvltrnavg {%eval( @lvltrnct/@lvltrnlvl).%eval( (( @lvltrnct\@lvltrnlvl) * 100)/@lvltrnlvl)} {} {GroupInfo|LevelInfo}

#VAR lvlbtrnavg {%eval( @lvlbtrnct/@lvltrnlvl).%eval( (( @lvlbtrnct\@lvltrnlvl) * 100)/@lvltrnlvl)} {} {GroupInfo|LevelInfo}

#VAR lvlbstatavg {%eval( @lvlbstats/@lvltrnlvl).%eval( (( @lvlbstats\@lvltrnlvl) * 100)/@lvltrnlvl)} {} {GroupInfo|LevelInfo}

#math lvlttrnlvl {@lvltrnct + @lvlbtrnct} {GroupInfo|LevelInfo}

#VAR lvlttrnavg {%eval( @lvlttrnlvl/@lvltrnlvl).%eval( (( @lvlttrnlvl\@lvltrnlvl) * 100)/@lvltrnlvl)} {} {GroupInfo|LevelInfo}

#if {%0} {%0 Since ~@W@lvltrreset~@Y: ~@C@lvltrnlvl~@Y levels. ~@C@lvltrnct ~@Ytrains. ~@C@lvlbtrnct~@Y bonus trains, ~@C@lvlbstats ~@Ybonus stats. ~@G@lvltrnavg ~@Ytrains per level. ~@G@lvlbtrnavg~@Y bonus trains per level. ~@G@lvlbstatavg~@Y bonus stats per level. ~@R@lvlttrnavg ~@Ytotal trains per level.} {@lichan Since ~@W@lvltrreset~@Y: ~@G@lvltrnlvl~@Y levels. ~@G@lvltrnct ~@Ytrains. ~@G@lvlbtrnct~@Y bonus trains, ~@C@lvlbstats ~@Ybonus stats. ~@C@lvltrnavg ~@Ytrains per level. ~@C@lvlbtrnavg~@Y bonus trains per level. ~@C@lvlbstatavg~@Y bonus stats per level. ~@R@lvlttrnavg ~@Ytotal trains per level.}
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Apr 24, 2005 7:47 pm   
 
Your problem is that you aren't checking for the existence of a single-digit number in the decimal portion of your variable calculations. ZMud doesn't retain or insert preceding zeros (ie, 09, 02, etc) unless it's working with decimal numbers (.09, .02, etc). You can use %len() to check the length of the result, and if it equates to 1 then add a preceding zero else do nothing.

%if(%len(the formula in the %eval()) = 1, "0","")
_________________
EDIT: I didn't like my old signature
Reply with quote
Atreides_096
Wanderer


Joined: 21 Jan 2005
Posts: 99
Location: Solvang, CA

PostPosted: Mon Apr 25, 2005 10:21 am   
 
Sorry if I'm a little dense here, but I couldn't find the proper placement to append this command into the above mentioned code. Could you give me an example? Thanks!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Apr 25, 2005 11:45 pm   
 
In your variables, you have two %eval() functions like so:

%eval(something).snippet goes here%eval(something)

I believe the proper way to do it is with a %concat() function, like so:

%concat(%eval(something), ".", %if(%len(the formula in the %eval()) = 1, "0",""), %eval(something))

where the bold parts are where you supply the correct info, but if the original code works for you I don't see much reason to change it.
_________________
EDIT: I didn't like my old signature
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