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
rtatum
Novice


Joined: 19 Sep 2004
Posts: 45
Location: Houston

PostPosted: Tue Sep 13, 2005 3:14 am   

Database variable math possible?
 
Is it possible to increment the value of a key in a database variable somehow?

Basically I'm trying to keep a list of fish cought, and how many...

So I get a message like "You reel - a pike - out of the water" and I want to have it increment the value of a key in a database, or some other such thing...
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Tue Sep 13, 2005 4:47 am   
 
yup...

Code:

#TRIGGER {You reel - &Key_name - out of the water} {
#LOOPDB @Fish_Database {#IF (@Key_Name = %key} {current_amount = %val;exists = 1}
#IF (@exists = 1) {#MATH current_amount @current_amount+1;exists = 0} {current_amount = 1}
#ADDKEY Fish_Database @Key_Name @current_amount}


This will add one to an existing record, or create a new record with a value of 1, or some other such thing :P
Reply with quote
rtatum
Novice


Joined: 19 Sep 2004
Posts: 45
Location: Houston

PostPosted: Tue Sep 13, 2005 5:24 am   
 
Hate to ask so many questions, but is there a way then to take the database variable, and have it output it to the mud in a say command in this format:

say Fishkey1: Value Fishkey2: Value Fishkey3: Value and so forth so it'll look like

Joe says: A pike: 4 A trout: 10 A minnow: 30
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Sep 13, 2005 5:45 am   
 
Ok There is an easier way to do the first part but too late to test it.

For the second part
#HELP %expanddb
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
rtatum
Novice


Joined: 19 Sep 2004
Posts: 45
Location: Houston

PostPosted: Tue Sep 13, 2005 6:44 am   
 
Got it working, and for future reference, what would the easier way have been?
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Tue Sep 13, 2005 10:15 am   
 
prolly without the second #IF??

Code:

#TRIGGER {You reel - &Key_name - out of the water} {
#LOOPDB @Fish_Database {#IF (@Key_Name = %key} {#MATH current_amount %val+1} {current_amount = 1}
#ADDKEY Fish_Database @Key_Name @current_amount}


i wrote it in a hurry :P sue me :)
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Sep 13, 2005 10:27 pm   
 
*Untested* should work with multiple word fish, and doesnt have the overhead that looping statements do.

#TRIGGER {You reel - (*) - out of the water} {
#ADDKEY Fish {%1} {%eval(@{fish.%1}+1)}
}
_________________
Zmud Support Library
Zmud Knowledge Base
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