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
Kaputchnik
Beginner


Joined: 06 Jan 2002
Posts: 28
Location: Sweden

PostPosted: Sun Mar 24, 2002 2:04 am   

#FORALL problems
 
When I check my inventory the last line I get up is how much money I am carrying. It could look in quite many different ways, since diffrent coins have different values and my mud doesnt show money types of which I am carrying 0 coins. Anyway to the problem. I am trying, based on the string, to calculate the total ammount of coins, thus converting every coin type to it's value in the highest coinvaluelevel. The coins are worth as follows:

copper : 1/500
silver : 1/50
electrum : 1/25
gold : 1/5
platinum : 1

With ofcourse Platnum coins being the most valuable. The string I receive from the mud looks like this:

Your purse contains 2 platinum, 11 gold, 22 silver and 2 copper coins.

And can ofcourse vary, can include/exclude any of the previous mentionend moneytypes. So instead of making a huge set of triggers I decided to use one trigger:

#trigger ^Your purse contains (*) coins.$

This would ofcourse leave me with the "2 platinum, 11 gold, 22 silver and 2 copper" string from previous mentioned example. Next I remove the ",":s and the "and", using:

#var temp %replace( "%1", ", ", "|")
#var temp %replace( @temp, " and ", "|")

This leaves me with the string "2 platinum|11 gold|22 silver|2 copper". And this is where my problam starts, I have been trying with hardly any success(since zMUD doesn't approve of my coding) but I simply can't get it to work. Here's what I got so far:

#forall @temp {
#if (%i="%d platinum") {
#var coins.platinum %int(%replace("%i"," platinum",""))
} {
#if (%i="%d gold") {
#var coins.gold %int(%replace("%i"," gold",""))
} {
#if (%i="%d electrum") {
#var coins.electrum %int(%replace("%i"," electrum",""))
} {
#if (%i="%d silver") {
#var coins.silver %int(%replace("%i"," silver",""))
} {
#if (%i="%d copper") {
#var coins.silver %int(%replace("%i"," copper",""))
} {} } } } }
#math coins.total (@coins.copper/500+@coins.silver/50+@coins.electrum/25+@coins.gold/5+@coins.platinum)


Been counting brackets and everything else I could think of. If anyone can solve my problem, I'd be grateful. Any enchancements are welcome as well.

Cheers,
Kaputchnik
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Sun Mar 24, 2002 4:53 am   
 
The conditional expression (%i="%d platinum") will not do what you want it to do. The interand is compared to it as a string, not as a pattern. I would suggest the following:


#forall @temp {#ADDKEY coins %word(%i, 2) %word(%i, 1)}
#math coins.total(@coins.copper/500+@coins.silver/50+@coins.electrum/25+@coins.gold/5+@coins.platinum)

I'm assuming you know that zMUD v. 6.16 only does integer division. You will not get a fractional result.


Troubadour
Reply with quote
Kaputchnik
Beginner


Joined: 06 Jan 2002
Posts: 28
Location: Sweden

PostPosted: Sun Mar 24, 2002 11:03 am   
 
Thanks, it worked perfectly, and much easier to understand. Since the lower valued coins are more common then the others, the result I get doesn't differ too much from the orginal(ie 1 platinum coins isn't worth that much really)

Cheers,
Kaputchnik
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