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
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Fri Jul 10, 2009 4:46 am   

#IF and numbers with a decimal point not working right
 
I feel like i should know this already....

Code:

#ALIAS SRTest2 {
 #IF (@SRNightCTemp <= @SRIslandTemp) {
   #VARIABLE SRPurchase NightClub
   #VARIABLE SRLowestTemp @SRNightCTemp
   #ADD SRTotalCost @SRNightCCost
 } {
   #VARIABLE SRPurchase Island
   #VARIABLE SRLowestTemp @SRIslandTemp
   #ADD SRTotalCost @SRIslandcost
 }
 #ECHO @SRPurchase - @addcommas( @SRTotalCost),000 Spent so far
}
#VAR SRIslandTemp {1337.5} {_nodef}
#VAR SRNightCTemp {1075} {_nodef}
#VAR SRIslandCost {2675000} {_nodef}
#VAR SRNightCCost {21500} {_nodef}

Run it and i get:
NightClub - 21,500,000 Spent so far
which is correct.

I decided to check and see if it would work if SRNightCTemp was higher, so i made it 10750, and i still get:
NightClub - 21,500,000 Spent so far

I take out the .5 in the SRIslandTemp and i get:
Island - 2,675,000,000 Spent so far

Why is the .5 throwing it off?
_________________
http://www.Aardwolf.com
Reply with quote
shalimar
GURU


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

PostPosted: Fri Jul 10, 2009 9:14 am   
 
i might think your trying to reference an illegal dbvariable....
_________________
Discord: Shalimarwildcat
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Fri Jul 10, 2009 5:17 pm   
 
"i might" or "IT might" ?
Cause if you do, then tell me why and how.

If IT might...then dang it how do i smack it around?
I can't believe that it can't handle comparing #'s because of a decimal point.
_________________
http://www.Aardwolf.com
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Fri Jul 10, 2009 7:33 pm   
 
Use the %int function (forces the value to be treated as an integer instead of a string value).

Charneus
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Jul 11, 2009 3:16 am   
 
This ties a little into your other question about really large numbers. ZMud stores everything in variables as strings, which essentially means that there's no limit to your variable sizes except to have enough bits in memory to record the actual length of the data (keep in mind that this is me looking in from the outside, so Zugg might have gone with a fancier approach involving Class Objects).

Because everything is in string format, ZMud uses some internal logic to autocast data into the appropriate type needed by each command/function. This logic gets mixed up or doesn't come into play if you work with variables as you are, so you need to force the issue with casting functions like the %int() Charneus suggested. Use %int() if you only want integers, use %float() if you want to retain decimals.
_________________
EDIT: I didn't like my old signature
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Sat Jul 11, 2009 6:11 am   
 
Char:
awesome on the %int()
#IF (%int( @SRNightCTemp) <= %int( @SRIslandTemp))
works perfect!

Matt:
Unsure if you meant that I should do this:

With the 000 added to both cost and gain:
#MATH SRIslandTemp %int(@SRIslandCost)/%int(@SRIslandGain)
Unfortunately, still gave me 1073 Crying or Very sad

As for the %float it's easier on the eyes to put .0 in the Gain variable.
#MATH SRIslandTemp %float(@SRIslandCost)/%float(@SRIslandGain)
#VAR SRNightCGain {20} {_nodef}
is just to busy for me in the math section

#MATH SRNightCTemp @SRNightCCost/@SRNightCGain
#VAR SRNightCGain {20.0} {_nodef}
just looks better to me

Remember, i'm the guy who's eyes watered and nearly burst trying to read cmud code ;-)
_________________
http://www.Aardwolf.com
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